-1

I am trying to persist an object into the database using Dropwizard's JPA annotation.

The object to be persisted

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();

    }

When I tru to get this resource I always get the error "Named Query not known". What have I missed

user_mda
  • 18,148
  • 27
  • 82
  • 145

1 Answers1

0

Got it, had the namedQuery syntax wrong. IT should have been @NamedQueries({ @NamedQuery( name = "", query = "" ) })

user_mda
  • 18,148
  • 27
  • 82
  • 145