When using sleep criteria, simply changing the connection type affects the results of the child collections of the root class of the domain.
For example, having the Parent class has a one-to-many relationship with the Child class with the following data:
Parent
| id | Name |
| 1 | Parent 1 |
Child
| id | parent_id | Name |
| 1 | 1 | Child1 |
| 2 | 1 | Child2 |
Using the following hibernation criteria returns 1 parent row, and access to the results of the child collection returns two rows:
session.createCriteria(Parent.class) .createCriteria('child', CriteriaSpecification.INNER_JOIN) .add( Restrictions.eq( 'name', 'Child1' ) ) .list()
However, when changing the above code with a left join, 1 parent row is returned, but when accessing the child collection, only the corresponding child row is returned.
session.createCriteria(Parent.class) .createCriteria('child', CriteriaSpecification.LEFT_JOIN) .add( Restrictions.eq( 'name', 'Child1' ) ) .list()
Why does this side effect occur? I found some discussion about using or avoiding this side effect depending on your intended outcome, but nothing about why it exists in the first place and whether it was intended. The closest direct question is the old obsolete defect ( http://opensource.atlassian.com/projects/hibernate/browse/HHH-3872 ).
- EDIT 3/24: Corrected data *
source share