When using the JPA 2.1 TYPE expression with a path expression such as "leaf.tree" an exception [1] occurs when executing the query. It should be valid according to the jpa 2.1 spec.
If the path expression is used as a join and the joined variable is used as the argument to the type expression the query works as expected.
An example is (the example can also be found in the attached test case):
select l from Leaf l where TYPE(l.tree) = PineTree gives the exception [1]
the following does work howerver select l from Leaf l join l.tree t where TYPE(t) = PineTree
[1]: 2015-05-22 11:50:20,756 ERROR SessionFactoryImpl - HHH000177: Error in named query: type-fails org.hibernate.QueryException: could not resolve property: class of: hibernatetypeissue.Leaf [select l from hibernatetypeissue.Leaf l where TYPE(l.tree) = PineTree] at org.hibernate.QueryException.generateQueryException(QueryException.java:137) at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:120) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:234) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:131) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:93) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167) at org.hibernate.internal.NamedQueryRepository.checkNamedQueries(NamedQueryRepository.java:161) at org.hibernate.internal.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:1090) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:536) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849) at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
|