title: Hibernate: Multiple select queries made by Hibernate for Fetch mode Eager
body: <p>I have just started using Hibernate in my application. Also I'm using JPA repository for using custom query. I have multiple entities which have relationships between them. I have used Fetch mode as 'EAGER' on the join column and also using Cache. I observed that Hibernate is making multiple select queries to fetch each entity and not doing it in a single query.</p>
  
  <p>Below is an entity:</p>
  
  <pre><code>@Entity
  @Table(name = "entity_a")
  public class EntityA implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      ...
  
      @OneToMany(fetch = FetchType.EAGER, mappedBy = "entity_a")
      @JsonIgnore
      @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
      private Set&lt;EntityB&gt; entityB = new HashSet&lt;&gt;();
  </code></pre>
  
  <p>I'm fetching my entity as below, using JPA custom queries:</p>
  
  <pre><code>EntityA entityA = entityARepository.findOneById(id);
  </code></pre>
  
  <p>Hibernate issues a select query for the above statement.</p>
  
  <p>Whenever I do a <code>entityA.getEntityB()</code> it issues another select statement on EntityB. How to avoid this. How can I get both entities in a single select using Hibernate?</p>