删除向导:用于从数据库中检索数据的"error processing your request"



当我尝试打开

http://localhost:8080/tailor/orders 

应该返回数据库中的所有订单。但是它正在生成错误

{"message":"There was an error processing your request. It has been logged (ID fe49a13e76c59894)."}

我无法追踪问题。

我正在使用dropwizard用于RESTFUL WEB服务,并从dropwizard for SQLIGHT数据库中使用。

类:

资源类:

@Path("/tailor")
@Produces(MediaType.APPLICATION_JSON)
public class TailorResource {
OrderDAO orderdao;
public TailorResource(OrderDAO odao) {
    this.orderdao = odao;
}

@GET
@Path("/orders")
@Produces(MediaType.APPLICATION_JSON)
public List<OrderModel> getAllOrders() {
    return orderdao.findAll();
}
@GET
@Path("/orders/{id}")
@Produces(MediaType.APPLICATION_JSON)
public OrderModel getOrderById(@PathParam("id") int id) {
    return orderdao.findById(id);
}
}

Orderdao类:

public class OrderDAO extends AbstractDAO<OrderModel>{

 public OrderDAO(SessionFactory sessionFactory) {
    super(sessionFactory);
}
  public OrderModel findById(int id) {
   return get(id);
}
public OrderModel create(OrderModel o) {
    return persist(o);
}
public List<OrderModel> findAll() {
    return list(namedQuery("com.yammer.dropwizard.tailor.model.OrderModel.findAll"));
}}

订单类:

@NamedQueries({
@NamedQuery(
    name = "com.yammer.dropwizard.tailor.model.OrderModel.findAll",
    query = "SELECT o FROM OrderModel o"
),
@NamedQuery(
    name = "com.yammer.dropwizard.tailor.model.OrderModel.findById",
    query = "SELECT o FROM OrderModel o WHERE o.ID = :ID"
)
})
@Entity
@Table(name = "Order")
public class OrderModel {
@Id
@GeneratedValue
@Column(name = "o_id")
int ID;
@Column(name = "o_shirt_quantity")
int shirtQuantity;
@Column(name = "o_longshirt_quantity")
int longshirtQuantity;
@Column(name = "o_trouser_quantity")
int trouserQuantity;
@Column(name = "o_coat_quantity")
int coatQuantity;
@Column(name = "o_deliverydate")
Date deliveryDate;
@Column(name = "o_orderdate")
Date orderDate;
@Column(name = "o_shirt_price")
Double shirtPrice;
@Column(name = "o_longshirt_price")
Double longshirtPrice;
@Column(name = "o_trouser_price")
Double trouserPrice;
 @Column(name = "o_coat_price")
Double coatPrice;
@Column(name = "o_totalamount")
Double totalAmount;
@Column(name = "o_discount")
Double discount;
@Column(name = "o_advancedpayment")
Double advancedPayment;
@Column(name = "o_remainingpayment")
Double remainingPayment;
@Column(name = "o_orderstatus")
int orderStatus;
}

数据库配置类:

public class databaseConfiguration extends Configuration {
@Valid
@NotNull
@JsonProperty
DataSourceFactory dbconfigurations = new DataSourceFactory();
public DataSourceFactory getDataSourceFactory() {
    //return dbconfigurations;
    Map<String,String> s=new HashMap<String,String>();
    s.put("hibernate.dialect","Hibernate.SQLightDialect.SQLiteDialect");
    dbconfigurations.setProperties(s);
    return dbconfigurations;
}
}

主服务类:

public class TailorApplication extends Application<databaseConfiguration> {
public static void main(String[] args) throws Exception {
    new TailorApplication().run(args);
}
private final HibernateBundle<databaseConfiguration> hibernate = new HibernateBundle<databaseConfiguration>(CustomerModel.class) {
     {
    @Override
    public DataSourceFactory getDataSourceFactory(databaseConfiguration configuration) {
        return configuration.getDataSourceFactory();
    }
};
@Override
public void initialize(Bootstrap<databaseConfiguration> bootstrap) {
    // TODO Auto-generated method stub
    bootstrap.addBundle(hibernate);
}
@Override
public void run(databaseConfiguration configuration, Environment environment)
        throws Exception {
      final OrderDAO odao = new OrderDAO(hibernate.getSessionFactory());
    environment.jersey().register(new TailorResource(odao));
}
}

yml文件:

dbconfigurations:
# the name of your JDBC driver
driverClass: org.sqlite.JDBC
# the username
user:
# the password
password:
url: jdbc:sqlite:TailorDB.db

请帮助?

确保您将申请类填写为实体:

private final HibernateBundle<AppConfiguration> hibernateBundle = new HibernateBundle<AppConfiguration>(
            //
            //
            //ADD ENTITIES HERE
            //
            //
            Person.class
            ,Product.class
            ) {
        @Override
        public DataSourceFactory getDataSourceFactory(
                AppConfiguration configuration) {
            return configuration.getDataSourceFactory();
        }
    };
  1. 在它的脸上,看起来您错过了Getallorders上的@unitofwork注释。

  2. 说,您共享的错误是DW默认提供的外部消息传递。相反,您应该查看您的Web服务日志,以获取确切的错误和精确的StackTrace。如果您使用Java -jar路径/to/shaded.jar Server my.yml在终端运行服务,则应在控制台上看到精心设计的错误。请分享,以便社区可以帮助更好。

相关内容

  • 没有找到相关文章

最新更新