Bug 1197937

Summary: [GSS](6.4.z)HHH-9637 - Join is reused when 2 explicit joins are used for the same ToOne association
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: unspecified Docs Contact:
Priority: unspecified    
Version: 6.3.2CC: bbaranow, bmaxwell, cdewolf, gbadner, istudens, jawilson, jmartisk, msimka, sfikes, smarlow
Target Milestone: CR1   
Target Release: EAP 6.4.3   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-01-17 10:39:27 UTC 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: 1231259, 1232160    
Attachments:
Description Flags
Maven based testcase adapted from original customer test none

Description Stephen Fikes 2015-03-03 02:01:36 UTC
Created attachment 997294 [details]
Maven based testcase adapted from original customer test

Description of problem:
https://hibernate.atlassian.net/browse/HHH-9637

Version-Release number of selected component (if applicable):
Change introduced by commit dd07167af8e1b4ab11489ce0a3bb7ed92f3ae257 first shipped as part of EAP 6.3.1 (hibernate-core-4.2.14.SP3-redhat-1.jar).

How reproducible:
Consistently

Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Consider the following schema (not the same as attached test which was adapted from what was originally provided by the customer)

@Entity Department {
    private String name;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "department")
    private List<Employee> employees;
}

@Entity Employee {
    private String name;

    @ManyToOne
    @JoinColumn(name = "dept_name")
    private Department department;
}

The following two queries are equivalent in result:

select d.*, e.*
from department d
inner join employee e on e.dept_name = d.name
inner join employee e2 on e2.dept_name = d.name
where e2.name = 'Mike Smith';

select d.*, e.*
from department d
inner join employee e on e.dept_name = d.name
-- inner join employee e2 on e2.dept_name = d.name
where d.name in (
    select d2.name
    from department d2
    inner join employee e2 on e2.dept_name = d2.name
    where e2.name = 'Mike Smith'
);

Both queries will discard any departments which don't include an employee named 'Mike Smith' and the results for both include all employees of any department which *does* include an employee named Mike Smith.

Comment 17 Gail Badner 2015-07-22 01:39:48 UTC
This is fixed upstream with the following commits to 4.2 branch:
* https://github.com/hibernate/hibernate-orm/commit/74f21115ce235f71769de3c363dbb88608ffc48f
* https://github.com/hibernate/hibernate-orm/commit/e740cb6238434432160b573bc3f765f48d8012ec (fixes test case only)

Comment 19 Jan Martiska 2015-07-30 12:41:34 UTC
Verified in EAP 6.4.3.CR1 / Hibernate 4.2.20.Final-redhat-1

Comment 21 Petr Penicka 2017-01-17 10:39:27 UTC
Retroactively bulk-closing issues from released EAP 6.4 cummulative patches.

Comment 22 Petr Penicka 2017-01-17 10:40:12 UTC
Retroactively bulk-closing issues from released EAP 6.4 cumulative patches.