<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Re: Services with missing/unavailable dependencies EntityManager
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/yvette_white">Evie White</a> in <i>JBoss AS7 Development</i> - <a href="http://community.jboss.org/message/619950#619950">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Scott &amp; Raphael,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I know what is happening in my situation. In short, I am receiving a "<strong>org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags</strong>" error. Based on some research and then verification, I have found that this is a Hibernate issue that results from using a FetchType.EAGER on a @OneToMany entity attribute where the attribute is a <strong>List</strong> collection. To fix the issue, there are two things that can be done: 1) do not use FetchType.EAGER (use the default of LAZY) or 2) use a Set as the collection type for the @OneToMany instead of a List.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I will provide sample code below that will demonstrate the problem.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>1. "TestDomain" - An Entity object that contains <span style="text-decoration: underline;">two</span> collections. Both are @OneToMany that use an EAGER fetch strategy and are contained in List collections. (This is the problem: can't use EAGER or can't use List; use Set, for example.)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">package foo.domain;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import java.util.List;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.CascadeType;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.Column;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.Entity;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.FetchType;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.GeneratedValue;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.GenerationType;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.Id;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.OneToMany;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.Table;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">@Entity</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">@Table(name="test")</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">public class TestDomain {</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @Id</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @GeneratedValue(strategy=GenerationType.IDENTITY)</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @Column(name="id")</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; private Long id;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @Column(name="name", length=255, nullable=false)</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; private String name;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @OneToMany(cascade={CascadeType.REMOVE}, fetch=<span style="color: #800000;">FetchType.EAGER</span>, mappedBy="test")</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; private <span style="color: #800000;">List</span>&lt;TestCommentDomain&gt; comments;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @OneToMany(cascade={CascadeType.REMOVE}, fetch=<span style="color: #800000;">FetchType.EAGER</span>, mappedBy="test")</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; private <span style="color: #800000;">List</span>&lt;TestPersonDomain&gt; persons;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public Long getId() {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; return id;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public void ListId(Long id) {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; this.id = id;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public String getName() {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; return name;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public void ListName(String name) {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; this.name = name;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public List&lt;TestCommentDomain&gt; getComments() {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; return comments;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public void ListComments(List&lt;TestCommentDomain&gt; comments) {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; this.comments = comments;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public List&lt;TestPersonDomain&gt; getPersons() {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; return persons;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public void ListPersons(List&lt;TestPersonDomain&gt; persons) {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; this.persons = persons;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>2. "TestCommentDomain" - An Entity object that is referenced by "TestDomain"</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">package foo.domain;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.Column;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.Entity;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.GeneratedValue;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.GenerationType;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.Id;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.JoinColumn;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.ManyToOne;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.Table;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">@Entity</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">@Table(name="test_comment")</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">public class TestCommentDomain {</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @Id</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @GeneratedValue(strategy=GenerationType.IDENTITY)</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @Column(name="id")</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; private Long id;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @ManyToOne(optional=false)</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @JoinColumn(name="test_id", nullable=false)</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; private TestDomain test;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @Column(name="comment", nullable=false)</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; private String comment;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public Long getId() {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; return id;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public void setId(Long id) {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; this.id = id;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public TestDomain getTest() {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; return test;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public void setTest(TestDomain test) {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; this.test = test;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public String getComment() {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; return comment;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public void setComment(String comment) {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; this.comment = comment;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>3. "TestPersonDomain" - A second Entity that is referenced by "TestDomain"</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 8pt; font-family: courier new,courier;">package foo.domain;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">import javax.persistence.Column;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">import javax.persistence.Entity;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">import javax.persistence.GeneratedValue;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">import javax.persistence.GenerationType;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">import javax.persistence.Id;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">import javax.persistence.JoinColumn;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">import javax.persistence.ManyToOne;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">import javax.persistence.Table;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 8pt; font-family: courier new,courier;">@Entity</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">@Table(name="test_person")</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">public class TestPersonDomain {</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; @Id</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; @GeneratedValue(strategy=GenerationType.IDENTITY)</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; @Column(name="id")</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; private Long id;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; @ManyToOne(optional=false)</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; @JoinColumn(name="test_id", nullable=false)</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; private TestDomain test;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; @Column(name="name", nullable=false)</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; private String name;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; public Long getId() {</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; return id;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; }</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; public void setId(Long id) {</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; this.id = id;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; }</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; public TestDomain getTest() {</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; return test;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; }</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; public void setTest(TestDomain test) {</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; this.test = test;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; }</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; public String getName() {</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; return name;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; }</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; public void setName(String name) {</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; this.name = name;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; }</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>4. "TestBean" - Remote interface for EJB stateless session bean.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 8pt; font-family: courier new,courier;">package foo.bean;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">import javax.ejb.Remote;</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">import foo.domain.TestDomain;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 8pt; font-family: courier new,courier;">@Remote</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">public interface TestBean {</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">&#160;&#160; public TestDomain find(Long id);</span></p><p><span style="font-size: 8pt; font-family: courier new,courier;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>5. "TestBeanImpl" - EJB stateless session bean implementation. This is where the PersistenceContext is used.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">package foo.bean.impl;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.ejb.Stateless;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.ejb.TransactionAttribute;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.ejb.TransactionAttributeType;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.EntityManager;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import javax.persistence.PersistenceContext;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import foo.bean.TestBean;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">import foo.domain.TestDomain;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">@Stateless</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">public class TestBeanImpl implements TestBean {</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; @PersistenceContext(unitName="bobo")</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; private EntityManager manager;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; public TestDomain find(Long id) {</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160; return manager.find(TestDomain.class, id);</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160; }</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>6. persistence.xml</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 8pt;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&lt;persistence</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160; xmlns="<a class="jive-link-external-small" href="http://java.sun.com/xml/ns/persistence" target="_blank">http://java.sun.com/xml/ns/persistence</a>"</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160; xmlns:xsi="<a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>"</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160; xsi:schemaLocation="<a class="jive-link-external-small" href="http://java.sun.com/xml/ns/persistence" target="_blank">http://java.sun.com/xml/ns/persistence</a> <a class="jive-link-external-small" href="http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" target="_blank">http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd</a>"</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160; version="2.0"&gt;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160; &lt;persistence-unit name="bobo"&gt;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;jta-data-source&gt;java:jboss/datasources/testDS&lt;/jta-data-source&gt;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;properties&gt;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /&gt;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;property name="show_sql" value="false" /&gt;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;property name="format_sql" value="true" /&gt;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;property name="use_sql_comments" value="false" /&gt;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/properties&gt;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&#160;&#160;&#160; &lt;/persistence-unit&gt;</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">&lt;/persistence&gt;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>7. portion of standalone.xml</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><table><tbody><tr><td style=";"><br/></td><td style=";"><span style="font-size: 8pt;">&lt;subsystem xmlns="urn:jboss:domain:datasources:1.0"&gt;</span></td></tr><tr><td style=";"><br/></td><td style=";">&lt;datasources&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;datasource jndi-name="java:jboss/datasources/testDS" pool-name="testDS" enabled="true" jta="true" use-java-context="true" use-ccm="true"&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;connection-url&gt;</td></tr><tr><td style=";"><br/></td><td style=";">jdbc:mysql://localhost:3306/bobo</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/connection-url&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;driver&gt;</td></tr><tr><td style=";"><br/></td><td style=";">mysql-connector-java-5.1.7-bin.jar</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/driver&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;pool&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;min-pool-size&gt;</td></tr><tr><td style=";"><br/></td><td style=";">1</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/min-pool-size&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;max-pool-size&gt;</td></tr><tr><td style=";"><br/></td><td style=";">5</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/max-pool-size&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;prefill&gt;</td></tr><tr><td style=";"><br/></td><td style=";">true</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/prefill&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;use-strict-min&gt;</td></tr><tr><td style=";"><br/></td><td style=";">false</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/use-strict-min&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;flush-strategy&gt;</td></tr><tr><td style=";"><br/></td><td style=";">FailingConnectionOnly</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/flush-strategy&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/pool&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;security&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;user-name&gt;</td></tr><tr><td style=";"><br/></td><td style=";">bobo_trx</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/user-name&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;password&gt;</td></tr><tr><td style=";"><br/></td><td style=";">Query123</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/password&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/security&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/datasource&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;drivers&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;driver name="h2" module="com.h2database.h2"&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;xa-datasource-class&gt;</td></tr><tr><td style=";"><br/></td><td style=";">org.h2.jdbcx.JdbcDataSource</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/xa-datasource-class&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/driver&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/drivers&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/datasources&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/subsystem&gt;</td></tr></tbody></table><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>8. Packaged into a JAR:</p><p><span style="font-family: courier new,courier; font-size: 8pt;">foo\bean\TestBean.class</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">foo\bean\impl\TestBeanImpl.class</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">foo\domain\TestCommentDomain.class</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">foo\domain\TestDomain.class</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">foo\domain\TestPersonDomain.class</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">META-INF\MANIFEST.MF</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">META-INF\persistence.xml</span></p><p><span style="font-family: courier new,courier; font-size: 8pt;">log4j.properties</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>9. A portion of the stack trace:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>11:53:52,662 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC00001: Failed to start service jboss.persistenceunit."test.jar#bobo": org.jboss.msc.service.StartException in service jboss.persistenceunit."test.jar#bobo": Failed to start service</p><p>&#160;&#160;&#160; at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1786)</p><p>&#160;&#160;&#160; at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)</p><p>&#160;&#160;&#160; at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_14]</p><p>&#160;&#160;&#160; at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_14]</p><p>&#160;&#160;&#160; at java.lang.Thread.run(Thread.java:619) [:1.6.0_14]</p><p>Caused by: javax.persistence.PersistenceException: [PersistenceUnit: bobo] Unable to build EntityManagerFactory</p><p>&#160;&#160;&#160; at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:903)</p><p>&#160;&#160;&#160; at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:879)</p><p>&#160;&#160;&#160; at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)</p><p>&#160;&#160;&#160; at org.jboss.as.jpa.service.PersistenceUnitService.createContainerEntityManagerFactory(PersistenceUnitService.java:170)</p><p>&#160;&#160;&#160; at org.jboss.as.jpa.service.PersistenceUnitService.start(PersistenceUnitService.java:80)</p><p>&#160;&#160;&#160; at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)</p><p>&#160;&#160;&#160; ... 4 more</p><p>Caused by: <span style="color: #800000;">org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags</span></p><p>&#160;&#160;&#160; at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:92)</p><p>&#160;&#160;&#160; at org.hibernate.loader.entity.EntityLoader.&lt;init&gt;(EntityLoader.java:118)</p><p>&#160;&#160;&#160; at org.hibernate.loader.entity.EntityLoader.&lt;init&gt;(EntityLoader.java:70)</p><p>&#160;&#160;&#160; at org.hibernate.loader.entity.EntityLoader.&lt;init&gt;(EntityLoader.java:53)</p><p>&#160;&#160;&#160; at org.hibernate.loader.entity.BatchingEntityLoader.createBatchingEntityLoader(BatchingEntityLoader.java:131)</p><p>&#160;&#160;&#160; at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1976)</p><p>&#160;&#160;&#160; at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1999)</p><p>&#160;&#160;&#160; at org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:3248)</p><p>&#160;&#160;&#160; at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:3234)</p><p>&#160;&#160;&#160; at org.hibernate.persister.entity.SingleTableEntityPersister.postInstantiate(SingleTableEntityPersister.java:770)</p><p>&#160;&#160;&#160; at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:419)</p><p>&#160;&#160;&#160; at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1720)</p><p>&#160;&#160;&#160; at org.hibernate.ejb.EntityManagerFactoryImpl.&lt;init&gt;(EntityManagerFactoryImpl.java:77)</p><p>&#160;&#160;&#160; at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:894)</p><p>&#160;&#160;&#160; ... 9 more</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>11:53:52,912 INFO&#160; [org.jboss.as.server.deployment] (MSC service thread 1-3) Stopped deployment test.jar in 6ms</p><p>11:53:52,912 INFO&#160; [org.jboss.as.server.deployment] (MSC service thread 1-3) Starting deployment of "test.jar"</p><p>11:53:52,912 INFO&#160; [org.jboss.as.server.controller] (DeploymentScanner-threads - 1) Replacement of deployment "test.jar" by deployment "test.jar" was rolled back with failure message {"Failed services" =&gt; {"jboss.persistenceunit.\"test.jar#bobo\"" =&gt; "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"test.jar#bobo\": Failed to start service"},"Services with missing/unavailable dependencies" =&gt; ["jboss.deployment.unit.\"test.jar\".jndiDependencyService missing [ jboss.naming.context.java.comp.test.test.TestBeanImpl.\"env/foo.bean.impl.TestBeanImpl/manager\" ]","jboss.deployment.unit.\"test.jar\".component.TestBeanImpl.START missing [ jboss.naming.context.java.comp.test.test.TestBeanImpl.\"env/foo.bean.impl.TestBeanImpl/manager\" ]"]}</p><p>11:53:52,912 INFO&#160; [org.jboss.jpa] (MSC service thread 1-3) read persistence.xml for bobo</p><p>11:53:52,928 INFO&#160; [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named TestBeanImpl in deployment unit deployment "test.jar" are as follows:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; java:global/test/TestBeanImpl!foo.bean.TestBean</p><p>&#160;&#160;&#160; java:app/test/TestBeanImpl!foo.bean.TestBean</p><p>&#160;&#160;&#160; java:module/TestBeanImpl!foo.bean.TestBean</p><p>&#160;&#160;&#160; java:global/test/TestBeanImpl</p><p>&#160;&#160;&#160; java:app/test/TestBeanImpl</p><p>&#160;&#160;&#160; java:module/TestBeanImpl</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/619950#619950">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss AS7 Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>