title: Caused by: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags
body: <p>I need to configure spring + JPA (EntityManager) + Hibernate . <br/>
  If I had to fetch = FetchType.LAZY run server success <br/>
  If I had to fetch = FetchType.EAGER run server error: <br/>
  I using tomcat 7
  <br/>
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: fmis2] Unable to build EntityManagerFactory  <br/>
  ...  <br/>
  Caused by: javax.persistence.PersistenceException: [PersistenceUnit: fmis2] Unable to build EntityManagerFactory   <br/>
  ...  <br/>
  Caused by: org.hibernate.loader.MultipleBagFetchException: can not simultaneously fetch multiple bags  <br/></p>
  
  <p>Please help me. Where I was wrong.
  Thanks</p>
  
  <p>Config applicationContext.xml</p>
  
  <pre><code>&lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="com.evnit.fmis" /&gt;
  &lt;jpa:repositories base-package="com.evnit.fmis" /&gt;
  &lt;!-- START --&gt;
  &lt;bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="persistenceXmlLocation" value="classpath:META-INF/jpa-persistence.xml" /&gt;
      &lt;property name="persistenceUnitName" value="fmis2" /&gt;
      &lt;property name="dataSource" ref="fmis2dataSource" /&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
              &lt;property name="showSql" value="false" /&gt;
              &lt;property name="databasePlatform" value="org.hibernate.dialect.SQLServerDialect" /&gt;
              &lt;property name="database" value="SQL_SERVER" /&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
      &lt;property name="loadTimeWeaver"&gt;
          &lt;bean
              class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /&gt;
      &lt;/property&gt;
  
  &lt;/bean&gt;
  
  &lt;bean id="fmis2dataSource" class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close"&gt;
      &lt;property name="driverClassName" value="${jdbc.driverClassName}" /&gt;
      &lt;property name="url" value="${jdbc.url}" /&gt;
      &lt;property name="username" value="${jdbc.username}" /&gt;
      &lt;property name="password" value="${jdbc.password}" /&gt;
  &lt;/bean&gt;
  &lt;bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;/bean&gt;
  &lt;tx:annotation-driven transaction-manager="txManager" /&gt;
  </code></pre>
  
  <p>jpa-persistence.xml</p>
  
  <pre><code>&lt;persistence-unit name="fmis2" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;jar-file&gt;/WEB-INF/lib/accounting-inf-1.0-SNAPSHOT.jar&lt;/jar-file&gt;
          &lt;jar-file&gt;/WEB-INF/lib/masterdata-inf-1.0-SNAPSHOT.jar&lt;/jar-file&gt;
          &lt;jar-file&gt;/WEB-INF/lib/congno-backend-1.0-SNAPSHOT.jar&lt;/jar-file&gt;
          &lt;jar-file&gt;/WEB-INF/lib/congcudungcu-backend-1.0-SNAPSHOT.jar&lt;/jar-file&gt;
          &lt;jar-file&gt;/WEB-INF/lib/taisan-backend-1.0-SNAPSHOT.jar&lt;/jar-file&gt;
          &lt;jar-file&gt;/WEB-INF/lib/vattu-backend-1.0-SNAPSHOT.jar&lt;/jar-file&gt;
          &lt;jar-file&gt;/WEB-INF/lib/muahang-backend-1.0-SNAPSHOT.jar&lt;/jar-file&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>Java Code entity</p>
  
  <pre><code>package com.evnit.fmis.accounting.entity;
  
  @Entity
  @Table(name = "ChungTu", schema = "ketoan")
  public class ChungTu implements java.io.Serializable {
  
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "chungTu")
      public List&lt;DinhKhoan&gt; getDinhKhoans() {
          return this.dinhKhoans;
      }
  
      public void setDinhKhoans(List&lt;DinhKhoan&gt; dinhKhoans) {
          this.dinhKhoans = dinhKhoans;
      }
  
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "chungTu")
      public List&lt;Uynhiemchi&gt; getUynhiemchis() {
          return this.uynhiemchis;
      }
  
      public void setUynhiemchis(List&lt;Uynhiemchi&gt; uynhiemchis) {
          this.uynhiemchis = uynhiemchis;
      }
  }
  @Entity
  @Table(name = "DinhKhoan", schema = "ketoan")
  public class DinhKhoan implements java.io.Serializable {
  
      private static final long serialVersionUID = 1L;
  
      private ChungTu chungTu;
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "IdChungtu")
      public ChungTu getChungTu() {
          return this.chungTu;
      }
  
      public void setChungTu(ChungTu chungTu) {
          this.chungTu = chungTu;
      }
  
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "dinhKhoan")
      public List&lt;HoaDonVat&gt; getHoaDonVats() {
          return this.hoaDonVats;
      }
  
      public void setHoaDonVats(List&lt;HoaDonVat&gt; hoaDonVats) {
          this.hoaDonVats = hoaDonVats;
      }
  
  }
  @Entity
  @Table(name = "Uynhiemchi", schema = "ketoan")
  public class Uynhiemchi implements java.io.Serializable {
  
      private ChungTu chungTu;
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "IdChungtu", nullable = true)
      public ChungTu getChungTu() {
          return this.chungTu;
      }
  
      public void setChungTu(ChungTu chungTu) {
          this.chungTu = chungTu;
      }
  
  }
  
  @Entity
  @Table(name = "HoaDonVAT", schema = "ketoan")
  public class HoaDonVat implements java.io.Serializable {
  
      private DinhKhoan dinhKhoan;
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "IdDinhKhoan")
      public DinhKhoan getDinhKhoan() {
          return this.dinhKhoan;
      }
  
      public void setDinhKhoan(DinhKhoan dinhKhoan) {
          this.dinhKhoan = dinhKhoan;
      }
  }
  </code></pre>
  
  <p>Java Code Dao</p>
  
  <pre><code> public abstract class CommonDao {
  
          @PersistenceContext(unitName = "fmis2")
          protected EntityManager entityManager;
      }
  </code></pre>