java.lang.NullPointerException

Hibernate JIRA | Christian Nelson | 9 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    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.

    Hibernate JIRA | 9 years ago | Christian Nelson
    java.lang.NullPointerException
  2. 0

    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.

    Hibernate JIRA | 9 years ago | Christian Nelson
    java.lang.NullPointerException
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.hibernate.loader.criteria.CriteriaLoader.applyLocks()
    2. Hibernate
      CriteriaLoader.list
      1. org.hibernate.loader.criteria.CriteriaLoader.applyLocks(CriteriaLoader.java:131)
      2. org.hibernate.loader.Loader.preprocessSQL(Loader.java:201)
      3. org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1538)
      4. org.hibernate.loader.Loader.doQuery(Loader.java:673)
      5. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
      6. org.hibernate.loader.Loader.doList(Loader.java:2213)
      7. org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
      8. org.hibernate.loader.Loader.list(Loader.java:2099)
      9. org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
      9 frames
    3. Hibernate
      CriteriaImpl.list
      1. org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
      2. org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
      2 frames