java.lang.NullPointerException

Hibernate JIRA | Antonio Anzivino | 6 months ago
  1. 0

    Finding the cause of this problem took me a lot of time, because unfortunately Hibernate was not helping me find the problem in the HQL. Now I want to help you track this insidious issue h2. Description of context I need to bulk delete entities based on a where condition. Nothing esoteric. But the column I am querying is based on a formula expression. In fact, for all of my linked entities I perform a double-mapping, as the handwritten example below. {code:java} class Entity{ @onetomany @joincolumn("roleid") private Role role; @formula("roleid") @private final String roleId = null; } class Role { @id@column("roleid") private String id; } {code} The following HQL does not work: {code:java} delete from com.acme.Entity item where item.roleId in (...) {code} However, navigating the relationship works {code:java} delete from com.acme.Entity item where item.role.id in (...) {code} Stack trace: {code:java} java.lang.NullPointerException at org.hibernate.internal.util.StringHelper.join(StringHelper.java:49) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.tree.DotNode.initText(DotNode.java:251) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:244) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:109) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:104) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:1013) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1286) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4713) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4497) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2130) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2055) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:813) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.deleteStatement(HqlSqlBaseWalker.java:455) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:275) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:302) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:240) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1907) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at com.acme.Dao.deleteAll {code} h2. Comment I want to report this as a bug because IMO the behaviour between select and delete is inconsistent (just replace "delete" with "from" keyword in the HQL and you get a query) AND because NPE is really really nasty, doesn't help you understand why the code failed, only that it failed for some reason. I don't see any reason to reject DELETEs based on the value of a Formula, especially if the formula reduces itself to a column and not a "real" formula. I would like to provide a test case but I am still new in reporting issues to Hibernate

    Hibernate JIRA | 6 months ago | Antonio Anzivino
    java.lang.NullPointerException
  2. 0

    Finding the cause of this problem took me a lot of time, because unfortunately Hibernate was not helping me find the problem in the HQL. Now I want to help you track this insidious issue h2. Description of context I need to bulk delete entities based on a where condition. Nothing esoteric. But the column I am querying is based on a formula expression. In fact, for all of my linked entities I perform a double-mapping, as the handwritten example below. {code:java} class Entity{ @onetomany @joincolumn("roleid") private Role role; @formula("roleid") @private final String roleId = null; } class Role { @id@column("roleid") private String id; } {code} The following HQL does not work: {code:java} delete from com.acme.Entity item where item.roleId in (...) {code} However, navigating the relationship works {code:java} delete from com.acme.Entity item where item.role.id in (...) {code} Stack trace: {code:java} java.lang.NullPointerException at org.hibernate.internal.util.StringHelper.join(StringHelper.java:49) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.tree.DotNode.initText(DotNode.java:251) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:244) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:109) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:104) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:1013) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1286) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4713) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4497) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2130) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2055) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:813) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.deleteStatement(HqlSqlBaseWalker.java:455) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:275) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:302) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:240) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1907) ~[hibernate-core-5.1.0.Final.jar:5.1.0.Final] at com.acme.Dao.deleteAll {code} h2. Comment I want to report this as a bug because IMO the behaviour between select and delete is inconsistent (just replace "delete" with "from" keyword in the HQL and you get a query) AND because NPE is really really nasty, doesn't help you understand why the code failed, only that it failed for some reason. I don't see any reason to reject DELETEs based on the value of a Formula, especially if the formula reduces itself to a column and not a "real" formula. I would like to provide a test case but I am still new in reporting issues to Hibernate

    Hibernate JIRA | 6 months ago | Antonio Anzivino
    java.lang.NullPointerException
  3. 0

    Support for summing Joda Money

    GitHub | 3 years ago | martypitt
    java.lang.NullPointerException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    tochar alias problem in h2 1.3.175 version

    Google Groups | 3 years ago | Ram
    java.lang.NullPointerException
  6. 0

    h2 database to_char alias throwing null pointer

    Stack Overflow | 3 years ago | user3443892
    java.lang.NullPointerException

    4 unregistered visitors
    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.internal.util.StringHelper.join()
    2. Hibernate
      SessionImpl.createQuery
      1. org.hibernate.internal.util.StringHelper.join(StringHelper.java:49)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      2. org.hibernate.hql.internal.ast.tree.DotNode.initText(DotNode.java:251)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      3. org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:244)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      4. org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:109)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      5. org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:104)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      6. org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:1013)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      7. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1286)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      8. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4713)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      9. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4497)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      10. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2130)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      11. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2055)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      12. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:813)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      13. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.deleteStatement(HqlSqlBaseWalker.java:455)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      14. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:275)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      15. org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      16. org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      17. org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      18. org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      19. org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      20. org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      21. org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:302)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      22. org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:240)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      23. org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1907)[hibernate-core-5.1.0.Final.jar:5.1.0.Final]
      23 frames