Query "select new pakage.Object ..." throws the ClassCastException when the
first level pakage is "by"
------------------------------------------------------------------------------------------------------
Key: HHH-7230
URL:
https://hibernate.onjira.com/browse/HHH-7230
Project: Hibernate ORM
Issue Type: Bug
Components: query-criteria, query-hql
Environment: hibernate-release-4.1.1.Final, Oracle 11.
Reporter: Anton Bastynets
Priority: Minor
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)
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira