mkuff mkuff - 1 year ago 125
Java Question

WebSphere 8.5 - Rest - No active Transaction

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)

I always get the following exception:

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
[29.08.13 15:14:59:714 CEST] 00000071 SystemErr R at
[29.08.13 15:14:59:714 CEST] 00000071 SystemErr R at
[29.08.13 15:14:59:714 CEST] 00000071 SystemErr R at com.TestFacade.testEMInsert(

My persistence.xml (placed in META-INF):

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="" xmlns:xsi=""

<!-- <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> -->
<!-- <provider></provider> -->


<!--<property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>-->
<property name="openjpa.Log" value="SQL=TRACE"/>
<!-- PrintParameters will show query parameters, remove when development has been finished -->
<!-- <property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true"/> -->
<property name="openjpa.jdbc.Schema" value="LKWSQL"/>
<property name="openjpa.TransactionMode" value="managed"/>
<property name="openjpa.ConnectionFactoryMode" value="managed"/>
<property name="openjpa.jdbc.DBDictionary" value="db2"/>

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.

@TransactionAttribute(TransactionAttributeType.REQUIRED) // default, but was worth a try
public class TestFacade implements ITestFacade {

private SearchService searchService;
private EntityManager em;

The search service caused the first troubles. With @EJB it always was null. @Inject from CDI worked. Maybe that's a clue?

@Produces({ MediaType.TEXT_PLAIN })
public String testEMInsert() {
System.out.println("testing Insert: " + em.isOpen()); // open is true
EntityTest e = new EntityTest("name");

} catch (Exception e){
return e.getMessage();

return "OK";

I hope anyone has an idea what i could check. Had to change the facade+service names. :-/

Answer Source

@mkuff - I develop an ear project that targets WAS v8.0.0.7.

All I need to get an EJB properly configured is this:

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
public class StateInfo {
    private EntityManager em;

To load the WAS 8.x.x libraries, my Maven pom uses the dependency:


As for the @SomeDatabase annotation...that's present because I leverage WAS's CDI (OpenWebBeans). Here's my Qualifier:

import javax.inject.Qualifier;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;

 * @author Chris Harris
public @interface SomeDatabase {}

Then, I use a Producer:

import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

 * @author Chris Harris
public class JPAResourceProducer {
@PersistenceContext(unitName = "somePuName")
private EntityManager em;

Here's my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
<persistence-unit name="somePuName" transaction-type="JTA">

Here's the relevant part of web.xml:

<resource-ref id="someDb">

And finally, ibm-web-bnd.xml:

<?xml version="1.0" encoding="UTF-8"?>

<virtual-host name="default_host" />

<resource-ref name="someDb" binding-name="jdbc/someDb" />

I have a DataSource defined in WAS that uses the name jdbc/someDb.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download