title: JPA (Hibernate) / QueryDSL left join with condition doesn't work
body: <p>I have two tables - <code>user</code> and <code>booking</code>. Each user may have many bookings (one-to-many relationship). </p>
  
  <pre><code>user:                          booking:
  
      id | name    |               id | country    | user_id | price   |
      -------------|               ------------------------------------|
       1 | Alice   |                1 | Italy      | 1       | 2000    |
       2 | Bob     |                2 | France     | 1       | 2500    |
                                    3 | Spain      | 1       | 3000    |
  </code></pre>
  
  <p>I want to select all users and all bookings where booking's price is greater than 2000 using <code>Query DSL</code>. If a user doesn't have any bookings or bookings don't match the condition I still want to select this user. </p>
  
  <p>First, let's have a look at how it would look like using a simple SQL left join query:</p>
  
  <pre><code>SELECT u.*, b.* FROM user u LEFT JOIN booking b ON u.id = b.user_id AND b.price &gt; 2000
  </code></pre>
  
  <p>The above query should provide the following result:</p>
  
  <pre><code>    id | name    | id    | country    | user_id | price   |
      -------------|----------------------------------------|
       1 | Alice   | 2     | France     | 1       | 2500    |
       1 | Alice   | 3     | Spain      | 1       | 3000    |
       2 | Bob     | null  | null       | null    | null    |
  </code></pre>
  
  <p>Now I want to do it using <code>JPA</code> with <code>Query DSL</code></p>
  
  <p><strong>JPA-related stuff:</strong></p>
  
  <pre><code>@Entity
  public class User {
  
      @Id
      private Long id;
      private String name;
  
      @OneToMany(cascade = ALL, fetch = EAGER, orphanRemoval = true, mappedBy = "user")
      private List&lt;Booking&gt; bookings;
  
      // getters and setters
  }
  
  @Entity
  public class Booking {
  
      @Id
      private Long id;
      private String name;
      private Integer price;
  
      @ManyToOne(fetch = LAZY)
      @JoinColumn(name = "user_id")
      private User user;
  
      // getters and setters
  }
  </code></pre>
  
  <p><strong>Query DSL:</strong></p>
  
  <pre><code>public List&lt;User&gt; getUsersAndBookings() {
      QUser user = QUser.user;
      QBooking booking = QBooking.booking;
  
      JPAQuery&lt;User&gt; jpaQuery = new JPAQuery(entityManager);
  
      List&lt;User&gt; result = jpaQuery.from(user).leftJoin(user.bookings, booking).on(booking.price.gt(2000)).fetchJoin().fetch();
  
      return result;
  }
  </code></pre>
  
  <p>In fact, this code is not working and I get the following exception:</p>
  
  <pre><code>org.hibernate.hql.internal.ast.QuerySyntaxException: with-clause not allowed on fetched associations; use filters [select user from com.example.demo.entity.User user left join fetch user.bookings as booking with booking.price &gt; ?1]
  </code></pre>
  
  <p>The problem is that the condition clause is specified in <code>on</code> method - <code>on(booking.price.gt(2000))</code>. </p>
  
  <p>After some research I found that this condition should be specified in <code>where</code> method and should look like this:</p>
  
  <pre><code>List&lt;User&gt; result = jpaQuery.from(user).leftJoin(user.bookings, booking).where(booking.price.gt(2000)).fetchJoin().fetch();
  </code></pre>
  
  <p>This works, but not how I would expect it to work, since it doesn't return ALL users, it returns only one user (Alice), which has some bookings, matching the condition clause. Basically, it just filters the merged table (result table after left join operation) and that's not what I'm looking for.</p>
  
  <p>I want to retrieve all users, and if there are no any bookings for a specific user, then just have <code>null</code> instead of booking list for this user.</p>
  
  <p>Please help, been struggling for hours without any success. </p>
  
  <p><hr/>
  Versions used:</p>
  
  <ul>
  <li>Spring Boot 2.0.2   </li>
  <li>Spring Data JPA 2.0.7  </li>
  <li>Hibernate 5.2.16.Final   </li>
  <li>QueryDSL 4.1.4</li>
  </ul>