[hibernate-dev] JPA 2.1 / EntityManagerFactory#addNamedQuery

Steve Ebersole steve at hibernate.org
Wed Jun 20 11:42:39 EDT 2012


JPA 2.1 adds an ability to add/override a named query using a "compiled" 
query object; javax.persistence.Query is the type passed in.

javax.persistence.Query just does not give access to the information 
needed to create a named query definition (at the most basic you cannot 
even get access to the original query string via 
javax.persistence.Query).  So this will have to be vendor specific; 
meaning Hibernate will need to do instanceof type checks on the incoming 
javax.persistence.Query object to make sure it is one we created (typed 
as org.hibernate.ejb.HibernateQuery) so that we can access the 
underlying org.hibernate.Query to get access to this information.

Unfortunately org.hibernate.Query also does not expose all the 
information we need.  The problem there is all the "query config" 
setters that have no corresponding getters (things like setMaxResults, 
setFirstResult, setCacheMode, etc).  I am right now just adding the 
needed getters to org.hibernate.Query.  If other projects implement 
org.hibernate.Query on their own, that obviously causes compatibility 
issues.  The other option is to instead create a "QueryImplementor" 
contract that adds these new getter methods.  I'd prefer not to do that, 
if we don't have to though.  So do other projects (hibernate search?, 
ogm?) implement this interface?

-- 
steve at hibernate.org
http://hibernate.org


More information about the hibernate-dev mailing list