retriving數據。當我試圖打開Dropwizard:「錯誤處理您的請求」從數據庫
http://localhost:8080/tailor/orders
應該返回database.but所有的命令它產生錯誤
{"message":"There was an error processing your request. It has been logged (ID fe49a13e76c59894)."}
我我無法追查這是什麼原因導致的問題。
我正在使用dropwizard進行寧靜的Web服務和從dropwizard進行休眠以執行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"));
}}
Order類:
@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
幫助嗎?
您是否嘗試過查看數據庫的日誌? – Magnilex
如何做到這一點?將在哪裏將日誌文件。新的所有這 –
我們甚至不知道你正在使用哪個數據庫。但閱讀這些文檔,我相信你會找到日誌文件。 – Magnilex