[hibernate-dev] JPA 2.1 / EntityManagerFactory#addNamedQuery

Sanne Grinovero sanne at hibernate.org
Wed Jun 20 12:07:11 EDT 2012


Indeed Hibernate Search (re)implements both
 - javax.persistence.Query
 - org.hibernate.Query

It would be nice if you could create a "Base" class for us to extend,
but not critically important: as discussed it just improves the odds
for different versions of Search to be compatible with ORM, when
people need to update one but the other isn't ready yet, or such a
double upgrade is not desired.

The general concept interests me more outside the scope of Search.

When is this "named query" going to be defined?
It would be extremely useful for the purpose of Hibernate OGM to have
an exhaustive list of the queries which are going to be needed at
initialization time, to potentially "tune" generated schema to
accommodate requirements of such queries.

In other words, I hope this "named query override" doesn't mean to
override named query definitions at runtime?

Sanne

On 20 June 2012 16:42, Steve Ebersole <steve at hibernate.org> wrote:
> 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
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev



More information about the hibernate-dev mailing list