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.