[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6902) Create typed query in EntityManager throws NullPointerException when filters are present

Ryan Bennett (JIRA) noreply at atlassian.com
Thu Dec 22 19:49:19 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6902?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44683#comment-44683 ] 

Ryan Bennett commented on HHH-6902:
-----------------------------------

We have also hit the same issue in versions 3.6.8 and 3.6.9. The issue occurs when we call count on any of our repositories (Spring Data JPA). The issue does not occur in 3.6.7.

> 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
>         Attachments: HibernateFilteredQueryError.zip
>
>
> 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