java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.ParameterNode cannot be cast to org.hibernate.hql.internal.ast.tree.SelectExpression

Hibernate JIRA | Christian Bauer | 4 years ago
  1. 0

    (There doesn't seem to be any test for CriteriaBuilder#selectCase().) This fails: {code} Root<User> u = criteria.from(User.class); criteria.select( cb.selectCase() .when( cb.equal(u.get("username"), "Foo"), "Bar" ).otherwise("Baz") ); {code} The actual query/entity mapping doesn't matter, any selectCase() expression with literals fails: {code} java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.ParameterNode cannot be cast to org.hibernate.hql.internal.ast.tree.SelectExpression at org.hibernate.hql.internal.ast.tree.CaseNode.getFirstThenNode(CaseNode.java:43) at org.hibernate.hql.internal.ast.tree.CaseNode.getDataType(CaseNode.java:39) at org.hibernate.hql.internal.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:152) at org.hibernate.hql.internal.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:859) at org.hibernate.hql.internal.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:649) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:663) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168) at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:270) at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:221) at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1778) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:538) at org.hibernate.jpa.criteria.CriteriaQueryImpl$1.buildCompiledQuery(CriteriaQueryImpl.java:376) at org.hibernate.jpa.criteria.compile.CriteriaCompiler.compile(CriteriaCompiler.java:128) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:679) {code} The rendered criteria query is using parameters for the literals: {code} select case when generatedAlias0.username=:param0 then :param1 else :param2 end from User as generatedAlias0 {code} The JPQL equivalent with simple literals and no parameters works: {code} select case when u.username='Foo' then 'Bar' else 'Baz' end from User as u {code}

    Hibernate JIRA | 4 years ago | Christian Bauer
    java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.ParameterNode cannot be cast to org.hibernate.hql.internal.ast.tree.SelectExpression
  2. 0

    (There doesn't seem to be any test for CriteriaBuilder#selectCase().) This fails: {code} Root<User> u = criteria.from(User.class); criteria.select( cb.selectCase() .when( cb.equal(u.get("username"), "Foo"), "Bar" ).otherwise("Baz") ); {code} The actual query/entity mapping doesn't matter, any selectCase() expression with literals fails: {code} java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.ParameterNode cannot be cast to org.hibernate.hql.internal.ast.tree.SelectExpression at org.hibernate.hql.internal.ast.tree.CaseNode.getFirstThenNode(CaseNode.java:43) at org.hibernate.hql.internal.ast.tree.CaseNode.getDataType(CaseNode.java:39) at org.hibernate.hql.internal.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:152) at org.hibernate.hql.internal.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:859) at org.hibernate.hql.internal.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:649) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:663) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168) at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:270) at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:221) at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1778) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:538) at org.hibernate.jpa.criteria.CriteriaQueryImpl$1.buildCompiledQuery(CriteriaQueryImpl.java:376) at org.hibernate.jpa.criteria.compile.CriteriaCompiler.compile(CriteriaCompiler.java:128) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:679) {code} The rendered criteria query is using parameters for the literals: {code} select case when generatedAlias0.username=:param0 then :param1 else :param2 end from User as generatedAlias0 {code} The JPQL equivalent with simple literals and no parameters works: {code} select case when u.username='Foo' then 'Bar' else 'Baz' end from User as u {code}

    Hibernate JIRA | 4 years ago | Christian Bauer
    java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.ParameterNode cannot be cast to org.hibernate.hql.internal.ast.tree.SelectExpression
  3. 0

    Hibernate ClassCastException IdentNode cannot cast to DotNode

    Stack Overflow | 3 years ago | dheerajarora
    java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.IdentNode cannot be cast to org.hibernate.hql.internal.ast.tree.DotNode
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    The problem appears, when class is placed in the package with first level "by", e.g. "by.bntu.shop.domain.dto.ProductDto". Test method: public void testExecSearchQuery1() { EntityManagerFactory emf = Persistence.createEntityManagerFactory("VideoShopPU"); EntityManager entityManager = emf.createEntityManager(); String queryStr = "SELECT new by.bntu.shop.domain.dto.ProductDto(c.id, c.price) FROM ProductEntity AS c"; TypedQuery<ProductDto> query = entityManager.createQuery(queryStr, ProductDto.class); //throws exception! List<ProductDto> results = query.getResultList(); } Stack trace: java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.FromReferenceNode at org.hibernate.hql.internal.ast.tree.DotNode.getLhs(DotNode.java:614) at org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:629) at org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:635) at org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:635) at org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:635) at org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:635) at org.hibernate.hql.internal.ast.tree.ConstructorNode.prepare(ConstructorNode.java:142) at org.hibernate.hql.internal.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:1021) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2126) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1992) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1433) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:559) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:287) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:106) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:81) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167) at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:217) at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:195) at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1649) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:296) at by.bntu.shop.unittests.ProductDaoTest.testExecSearchQuery1(ProductDaoTest.java:65)

    Hibernate JIRA | 5 years ago | Anton Bastynets
    java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.FromReferenceNode
  6. 0

    The problem appears, when class is placed in the package with first level "by", e.g. "by.bntu.shop.domain.dto.ProductDto". Test method: public void testExecSearchQuery1() { EntityManagerFactory emf = Persistence.createEntityManagerFactory("VideoShopPU"); EntityManager entityManager = emf.createEntityManager(); String queryStr = "SELECT new by.bntu.shop.domain.dto.ProductDto(c.id, c.price) FROM ProductEntity AS c"; TypedQuery<ProductDto> query = entityManager.createQuery(queryStr, ProductDto.class); //throws exception! List<ProductDto> results = query.getResultList(); } Stack trace: java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.FromReferenceNode at org.hibernate.hql.internal.ast.tree.DotNode.getLhs(DotNode.java:614) at org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:629) at org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:635) at org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:635) at org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:635) at org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:635) at org.hibernate.hql.internal.ast.tree.ConstructorNode.prepare(ConstructorNode.java:142) at org.hibernate.hql.internal.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:1021) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2126) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1992) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1433) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:559) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:287) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:106) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:81) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167) at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:217) at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:195) at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1649) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:296) at by.bntu.shop.unittests.ProductDaoTest.testExecSearchQuery1(ProductDaoTest.java:65)

    Hibernate JIRA | 5 years ago | Anton Bastynets
    java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.FromReferenceNode

    3 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.ClassCastException

      org.hibernate.hql.internal.ast.tree.ParameterNode cannot be cast to org.hibernate.hql.internal.ast.tree.SelectExpression

      at org.hibernate.hql.internal.ast.tree.CaseNode.getFirstThenNode()
    2. Hibernate
      SessionImpl.createQuery
      1. org.hibernate.hql.internal.ast.tree.CaseNode.getFirstThenNode(CaseNode.java:43)
      2. org.hibernate.hql.internal.ast.tree.CaseNode.getDataType(CaseNode.java:39)
      3. org.hibernate.hql.internal.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:152)
      4. org.hibernate.hql.internal.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:859)
      5. org.hibernate.hql.internal.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:649)
      6. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:663)
      7. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
      8. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
      9. org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
      10. org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
      11. org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
      12. org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
      13. org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
      14. org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
      15. org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:270)
      16. org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:221)
      17. org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1778)
      17 frames
    3. org.hibernate.jpa
      AbstractEntityManagerImpl.createQuery
      1. org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:538)
      2. org.hibernate.jpa.criteria.CriteriaQueryImpl$1.buildCompiledQuery(CriteriaQueryImpl.java:376)
      3. org.hibernate.jpa.criteria.compile.CriteriaCompiler.compile(CriteriaCompiler.java:128)
      4. org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:679)
      4 frames