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

Dan Luca (JIRA) noreply at atlassian.com
Fri Jan 13 08:46:10 EST 2012


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

Dan Luca commented on HHH-6902:
-------------------------------

I've been away for a while, but I agree with Steve - that is a better solution with less HQL plans created.
I'm glad to see this out in the 4.0.1 release.

> 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 ORM
>          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