It looks like you are mixing Hibernate-specific types and annotations with JPA types and annotations. SessionFactory and Session are Hibernate-specific classes, and session.getNamedQuery()
returns an object that implements org.hibernate.Query
, not javax.persistence.Query
.
On the other hand, javax.persistence.Query
is a JPA class and will be returned if you create the named query using JPA's EntityManager, e.g.:
javax.persistence.Query query = entityManager.createNamedQuery("LoadUserWithEmail");
Note also that there is a org.hibernate.annotations.NamedQuery
and a javax.persistence.NamedQuery
.
It is usually simpler to not mix the types and annotations of the two interfaces (SessionFactory vs JPA). If you use SessionFactory, you should stick with the Hibernate-specific types.