title: WebSphere 8.5 - Rest - No active Transaction
body: <p>I am struggling with WAS8.5 to use a simple Rest Service + an EJB to insert an entity into my DB2 database. Selecting works fine, because no transaction is needed.
  The Entity is correctly annotated. (successful select proves at least that)</p>
  
  <p>I always get the following exception:</p>
  
  <pre><code>javax.persistence.TransactionRequiredException: No active transaction for PuId=project.ear#included.war#persistence-unit-name
  [29.08.13 15:14:59:714 CEST] 00000071 SystemErr     R   at com.ibm.ws.jpa.management.JPATxEntityManager.getEMInvocationInfo(JPATxEntityManager.java:221)
  [29.08.13 15:14:59:714 CEST] 00000071 SystemErr     R   at com.ibm.ws.jpa.management.JPATxEntityManager.getEMInvocationInfo(JPATxEntityManager.java:179)
  [29.08.13 15:14:59:714 CEST] 00000071 SystemErr     R   at com.ibm.ws.jpa.management.JPAEntityManager.persist(JPAEntityManager.java:143)
  [29.08.13 15:14:59:714 CEST] 00000071 SystemErr     R   at com.TestFacade.testEMInsert(TestFacade.java:72)
  </code></pre>
  
  <p>My persistence.xml (placed in META-INF):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0"
      xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
      &lt;persistence-unit
                name="persistence-unit-name"
                transaction-type="JTA"&gt;
  
          &lt;!-- &lt;provider&gt;org.apache.openjpa.persistence.PersistenceProviderImpl&lt;/provider&gt; --&gt;
          &lt;!-- &lt;provider&gt;com.ibm.websphere.persistence.PersistenceProviderImpl&lt;/provider&gt; --&gt;
          &lt;jta-data-source&gt;jdbc/test-services-ds&lt;/jta-data-source&gt;
  
          &lt;class&gt;com.EntityTest&lt;/class&gt;
  
          &lt;properties&gt;
              &lt;!--&lt;property name="openjpa.RuntimeUnenhancedClasses" value="supported"/&gt;--&gt;
              &lt;property name="openjpa.Log" value="SQL=TRACE"/&gt;
              &lt;!-- PrintParameters will show query parameters, remove when development has been finished --&gt;
              &lt;!-- &lt;property name="openjpa.ConnectionFactoryProperties"  value="PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true"/&gt; --&gt;
              &lt;property name="openjpa.jdbc.Schema" value="LKWSQL"/&gt;
              &lt;property name="openjpa.TransactionMode" value="managed"/&gt;
              &lt;property name="openjpa.ConnectionFactoryMode" value="managed"/&gt;
              &lt;property name="openjpa.jdbc.DBDictionary" value="db2"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>The persistence.xml will be read so i think the packaging of the ear seems to be ok. I know in JavaEE6 a war would be sufficent, but it was already an existing project setup.
  The Team before us switched to user managed transactions, but i hope somebody can help me to point out the mistake.</p>
  
  <pre><code>@Stateless
  @TransactionAttribute(TransactionAttributeType.REQUIRED) // default, but was worth a try
  @Path("servicepath")
  public class TestFacade implements ITestFacade {
  
      @Inject
      private SearchService searchService;
      @PersistenceContext(unitName="persistence-unit-name")
      private EntityManager em;
  </code></pre>
  
  <p>The search service caused the first troubles. With @EJB it always was null. @Inject from CDI worked. Maybe that's a clue?</p>
  
  <pre><code>@GET
  @Path("testInsert/")
  @Produces({ MediaType.TEXT_PLAIN })
  public String testEMInsert() {
  try{
      System.out.println("testing Insert: " + em.isOpen()); // open is true
      EntityTest e = new EntityTest("name");
              em.persist(e);
  
  } catch (Exception e){
      e.printStackTrace();
      return e.getMessage();
  }
  
  return "OK";
   }
  </code></pre>
  
  <p>I hope anyone has an idea what i could check. Had to change the facade+service names. :-/
  greetings
  m</p>