[hibernate-issues] [Hibernate-JIRA] Closed: (HHH-6902) Create typed query in EntityManager throws NullPointerException when filters are present
Steve Ebersole (JIRA)
noreply at atlassian.com
Wed Jan 11 13:13:16 EST 2012
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6902?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Steve Ebersole closed HHH-6902.
-------------------------------
Prepping 4.0.1
> Create typed query in EntityManager throws NullPointerException when filters are present
> ----------------------------------------------------------------------------------------
>
> Key: HHH-6902
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6902
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 4.0.0.Final
> Environment: Oracle 11g; HibernateCore 4.0.0.Final; Spring 3.1.0
> Reporter: Dan Luca
> Assignee: Steve Ebersole
> Fix For: 4.0.1
>
> Attachments: HibernateFilteredQueryError.zip
>
> Time Spent: 16m
>
> I have an environment with JPA annotated entities, some with filters - e.g. filter out logically deleted entities. I have upgraded to hibernate 4 and discovered that {{javax.persistence.EntityManager.createQuery(String, Class<T>)}} throws a {color: red}NullPointerException{color} every time is invoked.
> I did some digging and here is what I have found:
> * calling {{entityManager.createQuery("query", resultType)}} on the current entity manager, ends up at {{org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(String, Class<T>)}}
> * this method does two things:
> *# creates the actual HQL query
> *# performs validation of the result type
> * step 2 above has the following call
> {code:title=AbstractEntityManagerImpl}
> final HQLQueryPlan queryPlan = unwrap( SessionImplementor.class )
> .getFactory()
> .getQueryPlanCache()
> .getHQLQueryPlan( jpaqlString, false, null );
> {code}
> Note the third argument in the {{QueryPlanCache.getHQLQueryPlan(String, boolean, Map)}} call is null. This argument is a raw +Map+ of enabled filters.
> * {{org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(String, boolean, Map)}} implementation creates a cache key from {color:navy}(queryString, shallowFlag, enabledFilters){color} tuple and if a plan exists it uses it, otherwise creates a brand new plan by invoking its constructor: {{new HQLQueryPlan(queryString, shallow, enabledFilters, factory )}}
> ** Note that the key created by step 1 above when there are filters defined, is +different+ from the one created with {{enabledFilters}} set to empty or null
> * the HQLQueryPlan constructor invokes *{color:red}{{enabledFilters.keySet()}}{color}* - hence the NPE
> I believe the correct invocation of the {{getHQLQueryPlan()}} at step 2 - for the purposes of validation - should be something like this instead:
> {{.getHQLQueryPlan( jpaqlString, false, *Collections.emptyMap())*}}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list