title: How to define JPA Repository Query with a Join?
body: <p>I would like to make a Join query by Jpa repository by annotation @Query I have three tables.</p>
  
  <p>The native query is:</p>
  
  <pre><code>select application.APP_ID 
  from user, customer, application 
  where user.USE_CUSTOMER_ID = customer.CUS_ID 
  and application.APP_CUSTOMER_ID = customer.CUS_ID 
  and user.USE_ID=1;
  </code></pre>
  
  <p>Now I have Table Hibernate entity, so I tried in ApplicationRepository</p>
  
  <pre><code>@Query(SELECT  application FROM  Application a
    INNER JOIN customer c ON c.customer.id = a.customer.id 
    INNER JOIN user u ON u.customer.id = c.customer.id
    INNER JOIN application a ON a.user.id = u.id
    WHERE
    u.id = :user.id)
  List&lt;Application&gt; findApplicationsByUser(@Param("User") User user);
  </code></pre>
  
  <p>The log says</p>
  
  <blockquote>
    <p>unexpected token</p>
  </blockquote>
  
  <p>Any ideas, please?</p>
  
  <p>My table Entity</p>
  
  <p><strong><em>Application.java:</em></strong></p>
  
  <pre><code>@Entity
  @Table
  public class Application extends BaseSimpleEntity {
  ...
      @ManyToOne(optional = false)
      private Customer customer;
  ...
  }
  </code></pre>
  
  <p><strong><em>Customer.java:</em></strong></p>
  
  <pre><code>@Entity
  @Table
  public class Customer extends BaseSimpleEntity {
  ...
      @OneToMany(mappedBy = "customer")
      private List&lt;User&gt; users;
      @OneToMany(mappedBy = "customer")
      private List&lt;Application&gt; applications;
  ...
  }
  </code></pre>
  
  <p><strong><em>User.java:</em></strong> </p>
  
  <pre><code>@Entity
  @Table
  public class User extends BaseSimpleEntity {
  ...
      @ManyToOne(optional = false)
      private Customer customer;
  ...
  }
  </code></pre>