Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate Child Collection Limited When Using Left Join in Criteria
    primarykey
    data
    text
    <p>When using hibernate criteria just altering the join type affects the results of the child collections of the root domain class.</p> <p>For instance, having class Parent have a one-to-many relationship with class Child with the following data:</p> <pre> Parent | id | Name | | 1 | Parent 1 | Child | id | parent_id | Name | | 1 | 1 | Child1 | | 2 | 1 | Child2 | </pre> <p>Using the following hibernate criteria returns the 1 parent row, and accessing the child collection results in the two rows being returned:</p> <pre><code>session.createCriteria(Parent.class) .createCriteria('child', CriteriaSpecification.INNER_JOIN) .add( Restrictions.eq( 'name', 'Child1' ) ) .list() </code></pre> <p>However, when changing the above code with a left join, the 1 parent row is returned, but only the matching child row is returned when accessing the child collection.</p> <pre><code>session.createCriteria(Parent.class) .createCriteria('child', CriteriaSpecification.LEFT_JOIN) .add( Restrictions.eq( 'name', 'Child1' ) ) .list() </code></pre> <p>Why does this side-effect occur? I found a few discussions about using or avoiding this side-effect depending on your intended result, but nothing about why it is there in the first place and whether it was intended. The closest direct question is an old stale defect (<a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-3872" rel="nofollow">http://opensource.atlassian.com/projects/hibernate/browse/HHH-3872</a>).</p> <ul> <li>EDIT 3/24: Fixed data *</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload