java.lang.NullPointerException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • If a named parameter of a named Query contains dots, the parser will throw an exception: 09:37:01,437 ERROR [PARSER] *** ERROR: <AST>:0:0: unexpected AST node: : 09:37:01,437 ERROR [Hibernate] Starting failed jboss.har:service=ReportingHibernate java.lang.NullPointerException at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:308) at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:767) at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:859) at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:3713) at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3193) at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1405) at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1330) at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:599) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:404) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83) at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:422) at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:383) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:286) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1055) at de.codebox.jboss.jmx.Hibernate.buildSessionFactory(Hibernate.java:503) The corresponding query is: <query name="de.codebox.testquery"><![CDATA[ from de.codebox.TestqueryObject as tqo where tqo.foreignReference.foreignClass =:bpofr.foreignClass and tqo.foreignReference.foreignId =:bpofr.foreignId order by tqo.idx ]]></query> If you omit the dots in the named parameters (e.g. bpofr_foreignClass and bpofr_foreignId) it works fine. As it is quite nasty to debug, it would at least be worth mentioning in the documentation. The same query worked with Hibernate2 (but obviously the parser is a complete rewrite anyway :-)
    via by Jochen Mersmann,
  • If a named parameter of a named Query contains dots, the parser will throw an exception: 09:37:01,437 ERROR [PARSER] *** ERROR: <AST>:0:0: unexpected AST node: : 09:37:01,437 ERROR [Hibernate] Starting failed jboss.har:service=ReportingHibernate java.lang.NullPointerException at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:308) at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:767) at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:859) at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:3713) at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3193) at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1405) at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1330) at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:599) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:404) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83) at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:422) at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:383) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:286) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1055) at de.codebox.jboss.jmx.Hibernate.buildSessionFactory(Hibernate.java:503) The corresponding query is: <query name="de.codebox.testquery"><![CDATA[ from de.codebox.TestqueryObject as tqo where tqo.foreignReference.foreignClass =:bpofr.foreignClass and tqo.foreignReference.foreignId =:bpofr.foreignId order by tqo.idx ]]></query> If you omit the dots in the named parameters (e.g. bpofr_foreignClass and bpofr_foreignId) it works fine. As it is quite nasty to debug, it would at least be worth mentioning in the documentation. The same query worked with Hibernate2 (but obviously the parser is a complete rewrite anyway :-)
    via by Jochen Mersmann,
  • As mentioned in summary, using a mapped POJO as the index of a <map..> relationship, via the <index-many-to-many class="..> approach. Using a table join, for instance: select index(depts), depts from ModificationFixed fixed left join fixed.departments depts Will fetch Department instances for each value, but if you instead try to fetch a property of the index: select index(depts).name, depts from ModificationFixed fixed left join fixed.departments depts then this causes the aforementioned NullPointerException, both in the hibernate tools preview, and in practise when trying to execute the query, with the following stack trace: Exception in thread "main" java.lang.NullPointerException at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:444) at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1080) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1881) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1825) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1394) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:553) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:115) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623) at intranet.db.PersistentMySQL.createQueryArray(PersistentMySQL.java:154) at intranet.budget.planner.ModificationFixed.main(ModificationFixed.java:165)
    via by James Andrews,
  • I have 2 mapped entities: EntityA [ id:long, testMap:Map<EnityB,Integer>, some other properties ] EntityB [ id:long, some other properties ] The mapping of EntityA is like: <class name="EntityA"> <id name="id">...</id> <map name="testMap" table="a_to_b"> <key column="a_id"/> <map-key-many-to-many column="b_id" class="EntityB"/> <element type="integer" column="int_value"/> </map> </class> Now I want to query all EntityA with a certain EnityB as map key: 1. "from a EntityA left join a.testMap b where index(b).id=?" Parameter: <Long> (id of an EntityB) 15:35:12,349 ERROR PARSER:56 - <AST>:1:94: unexpected AST node: ( java.lang.NullPointerException at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:534) at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4543) at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1289) at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4243) at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3722) at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1864) at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1792) at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:818) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:604) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:288) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651) [...] 2. "from a EntityA left join a.testMap b where index(b)=?" Parameter: <Long> (id of an EntityB) This is really strange: it tries to run the getter of EnityB.id againt a <Long> org.hibernate.PropertyAccessException: could not get a field value by reflection getter of test.EntityB.id at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:58) at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:199) at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3605) [...] Caused by: java.lang.IllegalArgumentException: Can not set long field test.EntityB.id to java.lang.Long at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146) at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150) at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37) at sun.reflect.UnsafeLongFieldAccessorImpl.getLong(UnsafeLongFieldAccessorImpl.java:42) at sun.reflect.UnsafeLongFieldAccessorImpl.get(UnsafeLongFieldAccessorImpl.java:18) at java.lang.reflect.Field.get(Field.java:358) at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:55) ... 67 more 3. "from a EntityA left join a.testMap b where index(b)=?" Parameter: <EntityB> 15:40:24,935 INFO IntegerType:158 - could not bind value '2009219112005957163' to parameter: 1; java.lang.Long cannot be cast to java.lang.Integer java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer at org.hibernate.type.IntegerType.set(IntegerType.java:64) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136) at org.hibernate.param.PositionalParameterSpecification.bind(PositionalParameterSpecification.java:68) at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:514) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1593) Here it thinks that the index() is of type integer.
    via by Michael Wyraz,
  • As mentioned in summary, using a mapped POJO as the index of a <map..> relationship, via the <index-many-to-many class="..> approach. Using a table join, for instance: select index(depts), depts from ModificationFixed fixed left join fixed.departments depts Will fetch Department instances for each value, but if you instead try to fetch a property of the index: select index(depts).name, depts from ModificationFixed fixed left join fixed.departments depts then this causes the aforementioned NullPointerException, both in the hibernate tools preview, and in practise when trying to execute the query, with the following stack trace: Exception in thread "main" java.lang.NullPointerException at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:444) at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1080) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1881) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1825) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1394) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:553) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:115) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623) at intranet.db.PersistentMySQL.createQueryArray(PersistentMySQL.java:154) at intranet.budget.planner.ModificationFixed.main(ModificationFixed.java:165)
    via by James Andrews,
  • I have 2 mapped entities: EntityA [ id:long, testMap:Map<EnityB,Integer>, some other properties ] EntityB [ id:long, some other properties ] The mapping of EntityA is like: <class name="EntityA"> <id name="id">...</id> <map name="testMap" table="a_to_b"> <key column="a_id"/> <map-key-many-to-many column="b_id" class="EntityB"/> <element type="integer" column="int_value"/> </map> </class> Now I want to query all EntityA with a certain EnityB as map key: 1. "from a EntityA left join a.testMap b where index(b).id=?" Parameter: <Long> (id of an EntityB) 15:35:12,349 ERROR PARSER:56 - <AST>:1:94: unexpected AST node: ( java.lang.NullPointerException at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:534) at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4543) at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1289) at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4243) at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3722) at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1864) at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1792) at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:818) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:604) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:288) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651) [...] 2. "from a EntityA left join a.testMap b where index(b)=?" Parameter: <Long> (id of an EntityB) This is really strange: it tries to run the getter of EnityB.id againt a <Long> org.hibernate.PropertyAccessException: could not get a field value by reflection getter of test.EntityB.id at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:58) at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:199) at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3605) [...] Caused by: java.lang.IllegalArgumentException: Can not set long field test.EntityB.id to java.lang.Long at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146) at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150) at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37) at sun.reflect.UnsafeLongFieldAccessorImpl.getLong(UnsafeLongFieldAccessorImpl.java:42) at sun.reflect.UnsafeLongFieldAccessorImpl.get(UnsafeLongFieldAccessorImpl.java:18) at java.lang.reflect.Field.get(Field.java:358) at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:55) ... 67 more 3. "from a EntityA left join a.testMap b where index(b)=?" Parameter: <EntityB> 15:40:24,935 INFO IntegerType:158 - could not bind value '2009219112005957163' to parameter: 1; java.lang.Long cannot be cast to java.lang.Integer java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer at org.hibernate.type.IntegerType.set(IntegerType.java:64) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136) at org.hibernate.param.PositionalParameterSpecification.bind(PositionalParameterSpecification.java:68) at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:514) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1593) Here it thinks that the index() is of type integer.
    via by Michael Wyraz,
    • java.lang.NullPointerException at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:308) at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:767) at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:859) at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:3713) at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3193) at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1405) at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1330) at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:599) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:404) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83) at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:422) at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:383) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:286) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1055) at de.codebox.jboss.jmx.Hibernate.buildSessionFactory(Hibernate.java:503)
    No Bugmate found.