title: Extra Cross Join with Spring Data JPA & Querydsl
body: <p>I am using Querydsl 2.9, Spring Data JPA 1.3.0 and Hibernate JPA 2 API version 1.0. I'm attempting to do a simple join between two tables, <code>Parent</code> and <code>Child</code>, joining on a <code>parentId</code> column. For some reason the query that is executed by Hibernate always has an extra <code>cross join</code> in it. The tables look like this:</p>
  
  <pre><code>CREATE TABLE PARENT (
      PARENTID INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
      NAME VARCHAR(255)
  );
  
  CREATE TABLE CHILD (
      CHILDID INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
      PARENTID INT(11),
      NAME VARCHAR(255)
  );
  </code></pre>
  
  <p>The domain classes look like this:</p>
  
  <pre><code>@Entity
  @Table(name="PARENT")
  public class Parent {
  
      @Id
      @GeneratedValue
      private Integer parentId;
  
      private String name;
  
      @OneToMany
      @JoinColumn(name="parentId")
      private List&lt;Child&gt; children;
  
      // ... getters/setters omitted for brevity
  }
  
  @Entity
  @Table(name="CHILD")
  public class Child {
  
      @Id
      @GeneratedValue
      private Integer childId;
  
      private Integer parentId;
  
      private String name;
  
      // ... getters/setters omitted for brevity
  }
  </code></pre>
  
  <p>My query code looks like this:</p>
  
  <pre><code>private List&lt;Parent&gt; test(List&lt;Integer&gt; parentIds) {
      JPAQuery query = new JPAQuery(entityManagerFactory.createEntityManager());
      QParent qParent = QParent.parent;
      QChild qChild = QChild.child;
  
      List&lt;Parent&gt; parents = query.from(qParent, qChild)
          .innerJoin(qParent.children, qChild)
          .where(qParent.parentId.in(parentIds))
          .list(qParent);
  
          return parents;
  }
  </code></pre>
  
  <p>I would expect the generated query to look something like this:</p>
  
  <pre><code>select 
      p.parentId, p.name 
  from 
      parent p
          inner join 
      child c on c.parentid = p.parentid 
  where 
      p.parentid in(1, 2);
  </code></pre>
  
  <p>However, the query that is actually run is this:</p>
  
  <pre><code>select 
      parent0_.parentId as parentId1_3_, parent0_.name as name2_3_
  from
      PARENT parent0_
          inner join
      CHILD children2_ ON parent0_.parentId = children2_.parentId
          cross join
      CHILD child1_
  where
      parent0_.parentId in (1 , 2);
  </code></pre>
  
  <p>Notice the extra <code>cross join</code> at the end. I realize I can get correct results if I do a <code>group by</code> on <code>childId</code>, but I don't want the extra overhead of the <code>cross join</code> when it's not necessary. I've tried using both <code>innerJoin</code> and <code>join</code> to no avail. I have scoured the Querydsl docs and I can see that the default join type is cross join, so perhaps I'm not specifying my join correctly? How do I get rid of the extra cross join?</p>