Note that there are some explanatory texts on larger screens.

plurals
  1. POeclipselink: Missing Transaction with different jar's
    text
    copied!<p>I have a JEE application. The classes of these JEE application are packaged in two different jar's which are both member of the EAR file.</p> <p>Let's say I have a JPA Entity "DataEntity" (packaged in the jar "a.jar"). </p> <p>In the first JAR file "a.jar" is also stored following class:</p> <pre><code>@Stateless @LocalBean public class A_Bean { @PersistenceContext(unitName = "testApp") private EntityManager em; public void testMethod(DataEntity obj) { if (em.contains(obj) log.info("CONTAINED a 1"); else { obj = em.merge(obj); em.refresh(obj); } if (em.contains(obj) log.info("CONTAINED a 2"); } } </code></pre> <p>In the second JAR file "b.jar" I have following class:</p> <pre><code>@Stateless @LocalBean public class B_Bean { @PersistenceContext(unitName = "testApp") private EntityManager em; public void testMethod(DataEntity obj) { if (em.contains(obj) log.info("CONTAINED b 1"); else { obj = em.merge(obj); em.refresh(obj); } if (em.contains(obj) log.info("CONTAINED b 2"); } } </code></pre> <p>Now I assume the following calls will be called from outside of the EJB container (means the specified DataEntity "dataObj" is currently not managed by the EntityManager):</p> <pre><code>a.testMethod(dataObj); </code></pre> <p>shows the expected output:</p> <pre><code>CONTAINED a 2 </code></pre> <p>But if I call </p> <pre><code>b.testMethod(dataObj); </code></pre> <p>I get a </p> <pre><code>Exception: javax.persistence.TransactionRequiredException at org.jboss.as.jpa.container.AbstractEntityManager.transactionIsRequired(AbstractEntityManager.java:692) at org.jboss.as.jpa.container.AbstractEntityManager.merge(AbstractEntityManager.java:547) at B_Bean.testMethod(B_Bean.java:xxx) ... </code></pre> <p>Also adding </p> <pre><code>@TransactionAttribute(TransactionAttributeType.REQUIRED) </code></pre> <p>not helps.</p> <p>And now after I moving the class B_Bean into the a.jar file also the B_Bean class works as expected.</p> <p>Must be packaged all EntityBeans in the same jar file? Is there is a trick how to package Entity classes in different jar files?</p> <p>My Environment:</p> <ul> <li>JBoss 7.1.1</li> <li>eclipselink 2.5.1</li> </ul> <p>Thanks, Steffen</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload