title: Hibernate pulls up all child records of a parent, not just the constrained children
body: <p>I got Cat entity which is parent, CatDts which is one to many child collection.
  I want to get all Cat which have CatDt.name='a'. The generated sql query is correct but when accessing the CatDts collection, all child recs are returned and not just those with name 'a'. Any help appreciated, thanks!</p>
  
  <p><strong>Tables</strong></p>
  
  <pre><code>Cat         CatDt
  id          id      name    cat_id
  ----        ---     ---     ---
  1           100     a       1
  2           101     a       2
              102     xyz     2
  </code></pre>
  
  <p>So I need just 1-100, 2-101 but it also gives me 2-102</p>
  
  <p><strong>Cat entity</strong></p>
  
  <pre><code>private List&lt;CatDt&gt; catDts = new ArrayList&lt;CatDt&gt;();
  
  @OneToMany(fetch = FetchType.LAZY, mappedBy = "cat", cascade=CascadeType.ALL)
  public List&lt;CatDt&gt; getCatDts() {
      if(this.catDts==null){
          this.catDts = new ArrayList&lt;CatDt&gt;();
      }
      return this.catDts;
  }
  </code></pre>
  
  <p><strong>CatDt entity</strong></p>
  
  <pre><code>private Cat cat;
  
  @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
      @JoinColumn(name = "CAT_ID", nullable = false)
  public Cat getCat() {
      return this.cat;
  }
  </code></pre>
  
  <p><strong>Service</strong></p>
  
  <pre><code>public List&lt;Cat&gt;findAllByOption(CatOption options){
      QCat cat = QCat.cat;
      QCatDt catDt = QCatDt.catDt;
      List&lt;Cat&gt; cats = jpaQueryFactory.selectFrom(cat)                
                  .innerJoin(catDt).on(cat.id.eq(catDt.cat.id).and(catDt.name.eq("a")))
                  .where(cat.status.eq(new BigDecimal(0))).fetch();
      return cats;
  }
  </code></pre>
  
  <p><strong>Test</strong></p>
  
  <pre><code>@Test
  public void testCatWithOptionsJpaQuery(){
      CatOption options = new CatOption();
      options.setStatus(new BigDecimal(0));
      options.setName("a");
      List&lt;Cat&gt; catList = catService.findAllByOption(options); //--&gt;returns 2 rows
      for(Cat cat:catList){
          logger.info("--" + cat.toString()); //--&gt;gets the child collection catDts and pulls out all rows, not just constrained ones
      }
      Assert.notNull(catList, "categories returned cannot be null!");
  }
  </code></pre>
  
  <p>I check logs and find, at below line of Test, sql query &amp; join is good, just returns 2 rows of Cat.</p>
  
  <pre><code>catService.findAllByOption(options)
  </code></pre>
  
  <p>But when I iterate those 2 Cat objects, Hibernate pulls out all correspoding CatDt child collection (total 3).
  So how do I get just the child records with name='a'?</p>
  
  <p><strong>Update 1</strong></p>
  
  <p>When execution reaches below line within the loop in Test, it throws up the individual select statements, that's how the 3 records are being returned instead of 2. I think this is how orm is supposed to work but how to get just constrained children?</p>
  
  <pre><code>logger.info("--" + cat.toString())
  </code></pre>