无法在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();
    }

当我试图获得这个资源时,我总是得到错误"命名查询不知道"。我错过了什么

明白了,namedQuery语法错误。它应该是@NamedQueries ({@NamedQuery (Name = ",查询= ")})

最新更新