Index: /Users/nicolas/Documents/EJB3_RC9_Patch_1/ejb3/src/main/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java =================================================================== --- /Users/nicolas/Documents/EJB3_RC9_Patch_1/ejb3/src/main/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java (revision 60675) +++ /Users/nicolas/Documents/EJB3_RC9_Patch_1/ejb3/src/main/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java (working copy) @@ -21,9 +21,11 @@ */ package org.jboss.ejb3.entity; +import java.util.IdentityHashMap; +import java.util.Map; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; -import javax.persistence.PersistenceContextType; import javax.persistence.TransactionRequiredException; import javax.transaction.RollbackException; import javax.transaction.Synchronization; @@ -29,15 +31,12 @@ import javax.transaction.Synchronization; import javax.transaction.SystemException; import javax.transaction.Transaction; + +import org.jboss.ejb3.ThreadLocalStack; +import org.jboss.ejb3.tx.TxUtil; import org.jboss.logging.Logger; import org.jboss.tm.TransactionLocal; -import org.jboss.tm.TxManager; import org.jboss.tm.TxUtils; -import org.jboss.ejb3.ThreadLocalStack; -import org.jboss.ejb3.tx.TxUtil; - -import java.util.IdentityHashMap; -import java.util.Map; /** * @author Gavin King @@ -56,11 +55,24 @@ public EntityManager getNonTxEntityManager() { Map map = nonTxStack.get(); - EntityManager em = (EntityManager)map.get(this); - if (em == null) - { - em = entityManagerFactory.createEntityManager(); - map.put(this, em); + EntityManager em = null; + if (map == null) { + + map = new IdentityHashMap(); + em = entityManagerFactory.createEntityManager(); + log.debug("Creating new em [" + em + "]"); + map.put(this, em); + nonTxStack.push(map); + } else { + em = (EntityManager)map.get(this); + + if (em == null) { + em = entityManagerFactory.createEntityManager(); + log.debug("Creating new em [" + em + "]"); + map.put(this, em); + } else + log.debug("reusing em [" + em + "]"); + } return em; } @@ -101,24 +113,25 @@ public void beforeCompletion() { - /* IF THIS GETS REACTIVATED THEN YOU MUST remove the if(closeAtTxCompletion) block in getSession() - try - { - int status = tx.getStatus(); - if (status != Status.STATUS_ROLLEDBACK && status != Status.STATUS_ROLLING_BACK && status != Status.STATUS_MARKED_ROLLBACK) - { - if (FlushModeInterceptor.getTxFlushMode() != FlushModeType.NEVER) - { - log.debug("************** flushing....."); - manager.flush(); - } - } - } - catch (SystemException e) - { - throw new RuntimeException(e); - } - */ + // IF THIS GETS REACTIVATED THEN YOU MUST remove the if(closeAtTxCompletion) block in getSession() +// try +// { +// int status = tx.getStatus(); +// if (status != Status.STATUS_ROLLEDBACK && status != Status.STATUS_ROLLING_BACK && status != Status.STATUS_MARKED_ROLLBACK) +// { +// if (manager.getFlushMode() != FlushModeType.COMMIT) +// { +// +// log.debug("************** flushing....."); +// manager.flush(); +// } +// } +// } +// catch (SystemException e) +// { +// throw new RuntimeException(e); +// } + } public void afterCompletion(int status) @@ -147,7 +160,7 @@ public void verifyInTx() { Transaction tx = session.getTransaction(); - if (tx == null || !TxUtils.isActive(tx)) throw new TransactionRequiredException("EntityManager must be access within a transaction"); + if (tx == null || !TxUtils.isActive(tx)) throw new TransactionRequiredException("EntityManager must be accessed within a transaction"); if (!TxUtils.isActive(tx)) throw new TransactionRequiredException("Transaction must be active to access EntityManager"); } Index: /Users/nicolas/Documents/EJB3_RC9_Patch_1/ejb3/src/main/org/jboss/ejb3/entity/PersistenceUnitDeployment.java =================================================================== --- /Users/nicolas/Documents/EJB3_RC9_Patch_1/ejb3/src/main/org/jboss/ejb3/entity/PersistenceUnitDeployment.java (revision 60675) +++ /Users/nicolas/Documents/EJB3_RC9_Patch_1/ejb3/src/main/org/jboss/ejb3/entity/PersistenceUnitDeployment.java (working copy) @@ -190,7 +190,7 @@ pi.setExcludeUnlistedClasses(xml.getExcludeUnlistedClasses()); pi.setPersistenceUnitRootUrl(di.getUrl()); PersistenceUnitTransactionType transactionType = PersistenceUnitTransactionType.JTA; - if ("RESOURCE_LOCAL".equals(xml.getTransactionType())) + if (PersistenceUnitTransactionType.RESOURCE_LOCAL.equals(xml.getTransactionType())) transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL; pi.setTransactionType(transactionType);