title: Fetching all entities with many to many relationships in repository layer : Hibernate with JPA
body: <p>in my current project, I am using Hibernate with JPA. </p>
  
  <p>I have entities as follows:</p>
  
  <p>Entity A:</p>
  
  <pre><code>@Entity
  @Table(name = "a")
  public class A implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GenericGenerator(name = "uuid", strategy = "uuid2")
      private String id;
  
      @Column(name = "name")
      private String name;
  
      @OneToMany
      private Set&lt;Association&gt; associations = new HashSet&lt;&gt;();
  }
  </code></pre>
  
  <p>Entity B:</p>
  
  <pre><code>    @Entity
      @Table(name = "b")
      public class B implements Serializable {
  
          private static final long serialVersionUID = 1L;
  
          @Id
          @GenericGenerator(name = "uuid", strategy = "uuid2")
          private String id;
  
          @Column(name = "description")
          private String description;
  
          @OneToMany
          private Set&lt;Association&gt; associations = new HashSet&lt;&gt;();
      }
  </code></pre>
  
  <p>Entity Association:</p>
  
  <pre><code>@Entity
  @Table(name = "association")
  public class Association implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
  
      @ManyToOne
      @JoinColumn(name = "a_id", referencedColumnName = "id")
      A a;
  
      @ManyToOne
      @JoinColumn(name = "b_id", referencedColumnName = "id")
      B b;
  
     ...other columns..
   }
  </code></pre>
  
  <p>Now I would like to implement repository layer for A as follows:</p>
  
  <pre><code>@Repository
  public interface ARepository extends JpaRepository&lt;A, Long&gt; {
  
      //Here I would like to write the function/query get all the As with many-to-many relationships.
  
  }
  </code></pre>