]
Michael Henderson commented on HHH-3313:
----------------------------------------
Ran into this recently. Using 3.6.7.Final, attempting to perform a Distinct projection
with LockMode.None.
Criteria + Property Projection + LockMode causes a NPE
------------------------------------------------------
Key: HHH-3313
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3313
Project: Hibernate Core
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&...
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-...).
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.
For more information on JIRA, see: