-1
我正在嘗試使用Dropwizard的JPA註釋將對象存入數據庫。無法獲得在dropwizard應用程序中工作的基本JPA
的對象被持久化
TheObject.java
@JsonIgnoreProperties(ignoreUnknown = true)
@Entity
@Table(name = "TheObject")
@NamedQuery(name = "com.comany.TheObject.findAll", query = "SELECT o FROM TheObject o")
public classTheObjectimplements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonProperty
String name;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "TheObject", fetch = FetchType.EAGER)
public void setName(String name) {
this.name = name;
}
public String getName(Long id) {
return this.name;
}
public TheObject (String name) {
this.name = name;
}
The data access object
public TheObjectDAO(SessionFactory factory) {
super(factory);
}
public List<TheObject> findAll() {
return list(namedQuery("com.comapny.TheObject.findAll"));
}
public TheObject create(TheObject o) {
return persist(o);
}
}
The Application class
public class TheApplication extends Application<AppConfiguration> {
private final static Logger log = Logger.getLogger(DeployerApplication.class.getName());
private final HibernateBundle<AppConfiguration> hibernate = new HibernateBundle<AppConfiguration>(
TheObject.class) {
public DataSourceFactory getDataSourceFactory(
AppConfiguration configuration) {
return configuration.getDataSourceFactory();
}
};
@Override
public void run(AppConfiguration configuration, Environment environment) throws SQLException {
final TheObjectDAO dao = new TheObjectDAO(hibernate.getSessionFactory());
environment.jersey().register(new TheObjectResource(dao));
And finally the resource class
public ObjectResource(TheObjectDAO edao) {
this.dao = dao;
}
@GET
@Timed
@UnitOfWork
public List<TheObject> getAllObjss() {
return dao.findAll();
}
當我TRU獲得這個資源,我總是得到錯誤「不知道命名查詢」。我錯過了什麼