Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1109449

Summary: (GSS)(6.4.0) HHH-9090: HQL: parser is trying to reuse parent implied join for subquery
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: Stephen Fikes <sfikes>
Component: HibernateAssignee: Gail Badner <gbadner>
Status: CLOSED CURRENTRELEASE QA Contact: Martin Simka <msimka>
Severity: urgent Docs Contact:
Priority: urgent    
Version: 6.2.3CC: cdewolf, dandread, kkhan, msimka
Target Milestone: DR11   
Target Release: EAP 6.4.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1118373 (view as bug list) Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1118373, 1121629    

Description Stephen Fikes 2014-06-14 03:55:35 UTC
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

Comment 3 Gail Badner 2014-08-13 18:08:32 UTC
This has been fixed in upstream 4.2 branch.

Comment 4 Gail Badner 2014-11-21 02:54:29 UTC
Fixed for EAP 6.4.0.

Comment 5 Kabir Khan 2014-11-21 11:34:54 UTC
Fixed by Hibernate 4.2.16.Final upgrade https://bugzilla.redhat.com/show_bug.cgi?id=1121629

Comment 6 Martin Simka 2014-11-27 12:13:21 UTC
verified on EAP 6.4.0.DR11 / Hibernate 4.2.16