The usage case of the EM is, that I call a PersistenceService.getEntityManager() method in every method of my SLSB's, the SLSBs all have
the "Required" attribute set for TXs, so every time I call the getEM() method, there should be an already running JTA TX.

This is the code:


logger.log(Level.FINEST,
"creating a fresh, clean EntityManager from JNDI EMF.");

// EntityManagerFactory emf = OpenJPAPersistence
// .createEntityManagerFactory(EMF_JNDI_LOCATION, (Context) null);

final EntityManagerFactory emf = getEMF();

final BrokerFactory bf = OpenJPAPersistence.toBrokerFactory(emf);

final Broker b = bf.newBroker(bf.getConfiguration()
.getConnectionUserName(), bf.getConfiguration()
.getConnectionPassword(), true, // the broker is part of a JTA  managed tx
bf.getConfiguration().getConnectionRetainModeConstant(), true); // look for an existing Broker on the tx

// do some JPA configuration setup. Logic stolen from
// EntityManagerFactoryImpl.
b.setAutoDetach(AutoDetach.DETACH_CLOSE, true);
b.setAutoDetach(AutoDetach.DETACH_ROLLBACK, true);
b.setDetachedNew(false);

return OpenJPAPersistence.toEntityManager(b);


And here you have the persistence.xml:

<persistence-unit name="lbsims" transaction-type="JTA">
<provider>
org.apache.openjpa.persistence.PersistenceProviderImpl
</provider>
<jta-data-source>jdbc_lbsims</jta-data-source>
<properties>
<property name="openjpa.ConnectionFactoryMode"
value="managed" />
<property name="openjpa.ManagedRuntime"
value="jndi(TransactionManagerName=java:comp/UserTransaction)" />
<property name="openjpa.DataCache" value="true"/>
<property name="openjpa.RemoteCommitProvider" value="sjvm"/>
</properties>
</persistence-unit>

hth,
HANS



Am Mittwoch, den 28.03.2007, 11:54 -0700 schrieb Patrick Linskey:
Also, how are you integrating it with the JTA transaction? Are you
calling EM.joinTransaction(), or ensuring that the transaction is in
progress before creating the EM, or something else?

-Patrick