title: Custom Query for fetching data from multiple tables in spring Data Jpa
body: <p>Entities are following </p>
  
  <p><strong>Product Table</strong></p>
  
  <pre><code>@Entity
  public class Product implements Serializable {
  /*@Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Integer id;*/
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;
  
      @NotNull(message = "Product name must not be null")
      @NotEmpty
      private String name;
  
  
      @ManyToOne
      @JoinColumn(name="category_id")
      private Category category;
  
      @ManyToMany(mappedBy = "productlist")
      private List&lt;OrderDetail&gt; orderDetail =new ArrayList&lt;OrderDetail&gt;();
  
  //getters setter
  </code></pre>
  
  <p><strong>OrderDetail Table</strong></p>
  
  <pre><code>@Entity
  public class OrderDetail {
  
       @Id
       @GeneratedValue(strategy = GenerationType.AUTO)
       private Integer id;
  
  
       @ManyToOne
       @JoinColumn(name="purchased_By")
       private user PurchasedBy;
  
  
      @ManyToMany
       private Set&lt;Product&gt; productlist = new HashSet&lt;Product&gt;();
  </code></pre>
  
  <blockquote>
    <p>These entities generating table named as 'order_detail_productlist'
    and fields as following    order_detail_id and productlist_id</p>
  </blockquote>
  
  <p>I am running following query in mysql editor and that is working </p>
  
  <pre><code>select u.id, r.name from order_detail u inner join order_detail_productlist ur on(u.id=ur.order_detail_id) inner join product r on(ur.productlist_id=r.id) where u.id="?"
  </code></pre>
  
  <p>but when i run in spring repository with @Query annotation that is giving me exception. I have tried to change name of Order_detail to OrderDetail according to entities but same exception in both case.</p>
  
  <pre><code>Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join! [select r.name from com.example.Domain.OrderDetail u inner join order_detail_productlist ur on(u.id=ur.order_detail_id) inner join Product r on(ur.productlist_id=r.id) where u.id= :id ]
  </code></pre>
  
  <p>what i want .
  i am trying to use in this way .</p>
  
  <pre><code>public final static String product_ordered ="select r.name from OrderDetail u inner join order_detail_productlist ur " +
              "on(u.id=ur.order_detail_id) inner join Product r" +
              " on(ur.productlist_id=r.id)" +
              " where u.id= :id ";
  
  @Query(product_ordered)
  public List&lt;Product&gt; findById(@Param("id") int id);
  </code></pre>
  
  <p>i want to get data from multiple tables , like products that are orderes etc . </p>