JPA is giving me an error when my application goes up. The error is in the named query:
org.hibernate.HibernateException: Errors in named queries: MyEntity.MyQuery org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:435)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:883)
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
The Entity code:
@NamedQuery(name = "MyEntity.MyQuery", query = "SELECT r FROM MyEntity r WHERE r.cdSecao = :secao AND r.cdPublico IN :publico")
// other class stuff declarations...
@JoinColumn(name = "cd_publico", referencedColumnName = "cd_publico")
@ManyToOne
private TbPublico cdPublico;
@JoinColumn(name = "cd_secao", referencedColumnName = "cd_secao")
@ManyToOne
private TbSecao cdSecao;
// getters setters and assorted shenanigans...
Then in the DAO, I invoke it with this method, even though the exception is being thrown at the init of the EntityManager (because its a named query and stuff). But for the sake of completeness, here it goes:
public List<MyEntity> listMyEntity(String idPublico, TbSecao secao) {
List<TbPublico> listaPublico = OtherClass.doMcGuffin(idPublico);
EntityManager em = EMFactory.getEntityManager();
TypedQuery<MyEntity> theQuery= em.createNamedQuery("MyEntity.MyQuery", MyEntity.class);
theQuery.setParameter("secao", secao);
theQuery.setParameter("publico", listaPublico);
return theQuery.getResultList();
}
Back to the named query... if I remove the AND r.cdPublico IN :publico it works, but I need it.