java.lang.ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.FromReferenceNode

Hibernate JIRA | Anton Bastynets | 5 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 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
  2. 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. 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

    (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
  6. 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 unregistered visitors

    Root Cause Analysis

    1. 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()
    2. Hibernate
      SessionImpl.createQuery
      1. org.hibernate.hql.internal.ast.tree.DotNode.getLhs(DotNode.java:614)
      2. org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:629)
      3. org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:635)
      4. org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:635)
      5. org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:635)
      6. org.hibernate.hql.internal.ast.tree.DotNode.getPath(DotNode.java:635)
      7. org.hibernate.hql.internal.ast.tree.ConstructorNode.prepare(ConstructorNode.java:142)
      8. org.hibernate.hql.internal.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:1021)
      9. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2126)
      10. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1992)
      11. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1433)
      12. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:559)
      13. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:287)
      14. org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235)
      15. org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
      16. org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
      17. org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
      18. org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:106)
      19. org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:81)
      20. org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167)
      21. org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:217)
      22. org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:195)
      23. org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1649)
      23 frames
    3. Hibernate EJB
      AbstractEntityManagerImpl.createQuery
      1. org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:296)
      1 frame
    4. by.bntu.shop
      ProductDaoTest.testExecSearchQuery1
      1. by.bntu.shop.unittests.ProductDaoTest.testExecSearchQuery1(ProductDaoTest.java:65)
      1 frame