title: CDI + JPA Multiple @OneToMany - LAZY/EAGER - LazyInitializationException OR Cannot instantiate multiple bags
body: <p>I am developing an application using Jboss AS 7, CDI, JPA, and some other resources bundled. </p>
  
  <p><strong>My question is:</strong> When I create a project in Eclipse using the maven-jboss-webapp-archetype it generates some files, which I have been extensively studying and trying to get along with. The problem is that sometimes I see myself a little bit confused whether I am using Hibernate resources or JPA resources. </p>
  
  <p>Second question: When I use multiple @OneToMany relationships in the same Entity I notice two behaviors: </p>
  
  <p>a) Without specifying EAGER type for Fetch, it deploys the application but when I try to use the list it gives me the LazyInitializationException error so vastly discussed here. </p>
  
  <p>b) When I specify Eager for the FetchType on the @*ToMany relationship it just doesnt deploys the application. It gives me the error: Cannot instantiate multiple bags. </p>
  
  <p>Here is the problematic piece of code:</p>
  
  <pre><code>@OneToMany(cascade = CascadeType.ALL, mappedBy = "teamUser" , fetch = FetchType.EAGER)
  private Collection&lt;Users&gt; usersCollection;
  
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "teamRanking" , fetch = FetchType.LAZY)
  private Collection&lt;Ranking&gt; rankingCollection;
  
  @NotNull
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "teamModality" , fetch = FetchType.LAZY)
  private Collection&lt;Modality&gt; modalitiesCollection;
  
  public Teams() {
  
  }
  
  public Teams(Long id_team , String name) {
      this.id = id_team;
      this.name = name;
  }
  </code></pre>
  
  <p>I have been reading about this and people told me that JPA does not support FetchType.EAGER for multiple realtionships in the same Entity. But I need to use multiple relationships in this entity in specific. I don't know what to do anymore, because I have tried several approaches, Lazy fetching, and all of them present some kind of issue. For example, if I leave only one FetchType.EAGER in the class then it deploys my app but it doesn't runs properly because when I try to fetch a List from the database it gives me the error: <strong>LazyInitializationException</strong>, and when I try to put all of them using the FetchType.EAGER it just doesnt deploy because it gives the error: Cannot instantiate multiple bags.</p>
  
  <p>So my issues here are related to:</p>
  
  <p>1) Maven-jboss-webapp-archetype uses hibernate or jpa or both?
  2) How can I attack this problem of using multiple @OneToMany relationships in an Entity? And although I know that fetching eagerly the Collections in the model is not the best approach because when the system grows I will probably have performance issues right? So how can I properly work with Lazy loading?</p>