Description of problem: org.hibernate.QueryException: could not resolve property: name of: TestClass2 [from TestClass1 as testClass1 where testClass1.testClass2.title='test2' and exists (from testClass1.testClass2.testClass3Set as testClass3 where testClass3.name = 'test3first')] See https://hibernate.atlassian.net/browse/HHH-9090 for further description Version-Release number of selected component (if applicable): Hibernate core 4.x How reproducible: Consistently Steps to Reproduce: See https://hibernate.atlassian.net/browse/HHH-9090 for full testcase 1. Create three entities with the following basic structure: @Entity public class TestClass1 implements Serializable { ... @OneToOne(fetch = FetchType.EAGER) private TestClass2 testClass2; ... } @Entity public class TestClass2 implements Serializable { ... @OneToMany private Set<TestClass3> testClass3Set = new HashSet<TestClass3>(); ... } @Entity public class TestClass3 implements Serializable { ... private String name; ... } 2. Execute the following query: String query = "from TestClass1 as testClass1 " + "where " + "testClass1.testClass2.title='test2' and " + "exists (from testClass1.testClass2.testClass3Set as testClass3 where testClass3.name = 'test3first')"; List a = hibernateSession.createQuery(query).list(); Actual results: org.hibernate.QueryException: could not resolve property: name of: TestClass2 [from TestClass1 as testClass1 where testClass1.testClass2.title='test2' and exists (from testClass1.testClass2.testClass3Set as testClass3 where testClass3.name = 'test3first')] 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:126) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190) ... Expected results: The query should run with no exception. Additional info: The following query (omitting only the first condition - which also works by itself) completes with no exception: from TestClass1 as testClass1 where exists (from testClass1.testClass2.testClass3Set as testClass3 where testClass3.name = 'test3first') Stepping through the code in the debugger, I think seems in the failing case we try to find the 'name' property in Set<TestClass3>. The root exception is raised first in the below stack: Thread [main] (Class load: QueryException) BasicEntityPropertyMapping(AbstractPropertyMapping).propertyException(String) line: 83 BasicEntityPropertyMapping(AbstractPropertyMapping).toType(String) line: 77 SingleTableEntityPersister(AbstractEntityPersister).getSubclassPropertyTableNumber(String) line: 1995 ... This occurs because the below returns null: typesByPropertyPath.get(propertyName); // AbstractPropertyMapping.java line 75
This has been fixed in upstream 4.2 branch.
Fixed for EAP 6.4.0.
Fixed by Hibernate 4.2.16.Final upgrade https://bugzilla.redhat.com/show_bug.cgi?id=1121629
verified on EAP 6.4.0.DR11 / Hibernate 4.2.16