java.lang.NullPointerException

Hibernate JIRA | Shelley J. Baker | 3 years ago
  1. 0

    A NullPointerException may be thrown from QueryImpl#extractParameterInfo: {noformat} java.lang.NullPointerException at org.hibernate.ejb.QueryImpl.extractParameterInfo(QueryImpl.java:114) at org.hibernate.ejb.QueryImpl.<init>(QueryImpl.java:97) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:467) at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:221) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:587) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241) {noformat} This appears to be a regression introduced in Hibernate 4.2.3 related to HHH-8283. This seems to occur when the right-hand operand contains an expression; e.g: {code} select ... where name=lower(?) {code} In the {{BinaryLogicOperatorNode#initialize}} method, the expected type of the node is never set and therefore remains null throughout. As a result, the new logic introduced in the {{QueryImpl#extractParameterInfo}} by HHH-8283 which obtains the corresponding class of the param's expected type now fails with an NPE.

    Hibernate JIRA | 3 years ago | Shelley J. Baker
    java.lang.NullPointerException
  2. 0

    A NullPointerException may be thrown from QueryImpl#extractParameterInfo: {noformat} java.lang.NullPointerException at org.hibernate.ejb.QueryImpl.extractParameterInfo(QueryImpl.java:114) at org.hibernate.ejb.QueryImpl.<init>(QueryImpl.java:97) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:467) at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:221) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:587) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241) {noformat} This appears to be a regression introduced in Hibernate 4.2.3 related to HHH-8283. This seems to occur when the right-hand operand contains an expression; e.g: {code} select ... where name=lower(?) {code} In the {{BinaryLogicOperatorNode#initialize}} method, the expected type of the node is never set and therefore remains null throughout. As a result, the new logic introduced in the {{QueryImpl#extractParameterInfo}} by HHH-8283 which obtains the corresponding class of the param's expected type now fails with an NPE.

    Hibernate JIRA | 3 years ago | Shelley J. Baker
    java.lang.NullPointerException
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    There is no value handler for date types defined in the ValueHandlerFactory class. This means that attempting to select a date literal will result in a null pointer exception. I ran into this bug when attempting to implement coalesce using date properties. The following code throws an exception: query.select(coalesce(pathToDatePropertyOnEntity, defaultDateLiteral)); Coalesce should select the date property off some entity unless it is null, in which case it will select the supplied date literal. But because no handling for date literals exists, this instruction throws a null pointer exception. Simple test case: @Test public void testFoo() throws Exception { //insert an element into the database Session session = sessionFactory.getCurrentSession(); session.beginTransaction(); SampleClass sample = new SampleClass(); session.save(sample); session.getTransaction().commit(); criteriaQuery.from(SampleClass.class); criteriaQuery.select(criteriaBuilder.literal(new Date())); TypedQuery<Date> jpaQuery = entityManager.createQuery(criteriaQuery); List<Date> results = jpaQuery.getResultList(); Assert.assertEquals(1, results.size()); } Test Output: DateLiteralJpaEvaluatorTest,testFoo Oct 29, 2013 10:37:56 AM org.hibernate.annotations.common.Version <clinit> INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final} Oct 29, 2013 10:37:56 AM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.2.5.Final} Oct 29, 2013 10:37:56 AM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found Oct 29, 2013 10:37:56 AM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Oct 29, 2013 10:37:57 AM org.hibernate.dialect.Dialect <init> INFO: HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect Oct 29, 2013 10:37:57 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory Oct 29, 2013 10:37:57 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init> INFO: HHH000397: Using ASTQueryTranslatorFactory Oct 29, 2013 10:37:57 AM org.hibernate.validator.internal.util.Version <clinit> INFO: HV000001: Hibernate Validator 5.0.0.Final Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000228: Running hbm2ddl schema update Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000102: Fetching database metadata Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000396: Updating schema Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata INFO: HHH000262: Table not found: SampleClass Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata INFO: HHH000262: Table not found: SampleClass Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata INFO: HHH000262: Table not found: SampleClass Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000232: Schema update complete create table SampleClass (id binary(255) not null, booleanProperty boolean, dateProperty timestamp, numberProperty numeric(19,2), stringProperty varchar(255), primary key (id)) Oct 29, 2013 10:37:58 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init> INFO: HHH000397: Using ASTQueryTranslatorFactory Oct 29, 2013 10:37:58 AM org.hibernate.type.TypeFactory$TypeScopeImpl injectSessionFactory WARN: HHH000233: Scoping types to session factory org.hibernate.internal.SessionFactoryImpl@7a8eb36a after already scoped org.hibernate.internal.SessionFactoryImpl@5dd23619 java.lang.NullPointerException at org.hibernate.ejb.criteria.expression.LiteralExpression.renderProjection(LiteralExpression.java:82) at org.hibernate.ejb.criteria.QueryStructure.render(QueryStructure.java:250) at org.hibernate.ejb.criteria.CriteriaQueryImpl.render(CriteriaQueryImpl.java:338) at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:223) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:622) at com.tr.grc.storage.eval.jpa.date.DateLiteralJpaEvaluatorTest.testFoo(DateLiteralJpaEvaluatorTest.java:78) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

    Hibernate JIRA | 3 years ago | Mike Wilklow
    java.lang.NullPointerException
  5. 0

    There is no value handler for date types defined in the ValueHandlerFactory class. This means that attempting to select a date literal will result in a null pointer exception. I ran into this bug when attempting to implement coalesce using date properties. The following code throws an exception: query.select(coalesce(pathToDatePropertyOnEntity, defaultDateLiteral)); Coalesce should select the date property off some entity unless it is null, in which case it will select the supplied date literal. But because no handling for date literals exists, this instruction throws a null pointer exception. Simple test case: @Test public void testFoo() throws Exception { //insert an element into the database Session session = sessionFactory.getCurrentSession(); session.beginTransaction(); SampleClass sample = new SampleClass(); session.save(sample); session.getTransaction().commit(); criteriaQuery.from(SampleClass.class); criteriaQuery.select(criteriaBuilder.literal(new Date())); TypedQuery<Date> jpaQuery = entityManager.createQuery(criteriaQuery); List<Date> results = jpaQuery.getResultList(); Assert.assertEquals(1, results.size()); } Test Output: DateLiteralJpaEvaluatorTest,testFoo Oct 29, 2013 10:37:56 AM org.hibernate.annotations.common.Version <clinit> INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final} Oct 29, 2013 10:37:56 AM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.2.5.Final} Oct 29, 2013 10:37:56 AM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found Oct 29, 2013 10:37:56 AM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Oct 29, 2013 10:37:57 AM org.hibernate.dialect.Dialect <init> INFO: HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect Oct 29, 2013 10:37:57 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory Oct 29, 2013 10:37:57 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init> INFO: HHH000397: Using ASTQueryTranslatorFactory Oct 29, 2013 10:37:57 AM org.hibernate.validator.internal.util.Version <clinit> INFO: HV000001: Hibernate Validator 5.0.0.Final Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000228: Running hbm2ddl schema update Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000102: Fetching database metadata Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000396: Updating schema Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata INFO: HHH000262: Table not found: SampleClass Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata INFO: HHH000262: Table not found: SampleClass Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata INFO: HHH000262: Table not found: SampleClass Oct 29, 2013 10:37:58 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000232: Schema update complete create table SampleClass (id binary(255) not null, booleanProperty boolean, dateProperty timestamp, numberProperty numeric(19,2), stringProperty varchar(255), primary key (id)) Oct 29, 2013 10:37:58 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init> INFO: HHH000397: Using ASTQueryTranslatorFactory Oct 29, 2013 10:37:58 AM org.hibernate.type.TypeFactory$TypeScopeImpl injectSessionFactory WARN: HHH000233: Scoping types to session factory org.hibernate.internal.SessionFactoryImpl@7a8eb36a after already scoped org.hibernate.internal.SessionFactoryImpl@5dd23619 java.lang.NullPointerException at org.hibernate.ejb.criteria.expression.LiteralExpression.renderProjection(LiteralExpression.java:82) at org.hibernate.ejb.criteria.QueryStructure.render(QueryStructure.java:250) at org.hibernate.ejb.criteria.CriteriaQueryImpl.render(CriteriaQueryImpl.java:338) at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:223) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:622) at com.tr.grc.storage.eval.jpa.date.DateLiteralJpaEvaluatorTest.testFoo(DateLiteralJpaEvaluatorTest.java:78) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

    Hibernate JIRA | 3 years ago | Mike Wilklow
    java.lang.NullPointerException

  1. linxiaolong 2 times, last 2 months ago
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.NullPointerException

    No message provided

    at org.hibernate.ejb.QueryImpl.extractParameterInfo()
  2. Hibernate EJB
    AbstractEntityManagerImpl.createQuery
    1. org.hibernate.ejb.QueryImpl.extractParameterInfo(QueryImpl.java:114)
    2. org.hibernate.ejb.QueryImpl.<init>(QueryImpl.java:97)
    3. org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:467)
    4. org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:221)
    5. org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:587)
    5 frames
  3. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    4. java.lang.reflect.Method.invoke(Method.java:601)
    4 frames
  4. Spring ORM
    SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke
    1. org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241)
    1 frame