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

Dan Luca (JIRA) noreply at atlassian.com
Tue Dec 20 14:12:19 EST 2011


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6902?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dan Luca updated HHH-6902:
--------------------------

    Attachment: HibernateFilteredQueryError.zip

Attached project with setup and test case exposing the problem. Within the log folder, the TypedQueriesFilter.log shows the error encountered when using typed  queries with filters enabled. Note that untyped queries work just fine.

> 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