[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3313) Criteria + Property Projection + LockMode causes a NPE

Christian Nelson (JIRA) noreply at atlassian.com
Thu May 29 15:53:33 EDT 2008


Criteria + Property Projection + LockMode causes a NPE
------------------------------------------------------

                 Key: HHH-3313
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3313
             Project: Hibernate3
          Issue Type: Bug
          Components: query-criteria
    Affects Versions: 3.2.6
         Environment: Hibernate 3.2.6.ga, PostgreSQL 8.1
            Reporter: Christian Nelson
         Attachments: hibernate-criteria-projection-lockmode-project.zip

In converting a working HQL query to the Criteria API, we stumbled upon what looks very much like a bug.  When combining a criteria with a projection and setting the lockmode (to read or upgrade), hibernate throws a NPE down in CriteriaLoader.applyLocks().

Here's a simplified snippet of the criteria that results in the exception:

        Criteria criteria = session.createCriteria(Article.class).add(Restrictions.ilike("title", "%frozen%"));
        criteria.createCriteria("moderation", "m").add(Restrictions.eq("approved", true));
        criteria.setProjection(Projections.property("moderation"));
        criteria.setLockMode("m", LockMode.UPGRADE);
        assertions(criteria.list());

[The test case includes other attempts at building a similar criteria using different approaches.]

And here's the stack trace:

    java.lang.NullPointerException
        at org.hibernate.loader.criteria.CriteriaLoader.applyLocks(CriteriaLoader.java:131)
        at org.hibernate.loader.Loader.preprocessSQL(Loader.java:201)
        at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1538)
        at org.hibernate.loader.Loader.doQuery(Loader.java:673)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
        at org.hibernate.loader.Loader.doList(Loader.java:2213)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
        at org.hibernate.loader.Loader.list(Loader.java:2099)
        at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
        at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)

There's already some talk on the web about this problem:

* http://forum.hibernate.org/viewtopic.php?t=955525
* http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=78&t=003636

I've created a simplified test case which includes the HQL version of the query (works), the Criteria version without lockmode (works), and then 3 failing tests illustrating the problem.  The attached zip contains the test case and supporting files. The source code for the test case is also available via anonymous svn access (http://svn.carbonfive.com/public/christian/hibernate-criteria-projection-lockmode/trunk).  The test will run out of the box using maven against an h2database in-memory database with no setup.

This combination of features doesn't seem that obscure so I'd expect it to work, or at the very least, report that it is not supported in a more graceful manner.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list