title: JPA load multiple lazy collections
body: <p>I have following entities:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  public class ProjectEntity implements Project {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      @ManyToOne(targetEntity =  FlowEntity.class)
      private Flow flow;
  }
  
  @Entity
  public class FlowEntity implements Flow {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long id;
  
      @OneToMany(targetEntity = StepEntity.class, fetch = FetchType.EAGER)
      private List&lt;Step&gt; steps;
  }
  
  @Entity
  public class StepEntity implements Step {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      @ManyToMany(targetEntity = ResourceEntity.class, fetch = FetchType.LAZY)
      private List&lt;Resource&gt; resources;
  
      @OneToMany(targetEntity = StepRuleEntity.class, fetch = FetchType.LAZY)
      private List&lt;StepRule&gt; rules;
  
      @ManyToMany(targetEntity = ResourceTypeDataEntity.class, fetch = FetchType.LAZY)
      private List&lt;ResourceTypeData&gt; resourceTypeData;
  }
  </code></pre>
  
  <p>Now when I retrieve my project I want that everything is loaded. I can't make everything eager loaded because it will just slow everything down. But for this functionality I now really need everything from the project. </p>
  
  <p>I read on the internet that you need to call <code>.size()</code> method on every collection and that jpa will then load the collections but it doesn't work. Plus I find it really strange that I need to do a <code>for</code> loop in my dao on every step of the flow to load the next lazy loaded collections.</p>
  
  <p>My method is annotated with <code>@Transactional</code> to fetch the project and it's a default <code>JpaRepostitory</code>.</p>
  
  <p>How do you do this properly? </p>