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) @@ -23,9 +23,11 @@ import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; +import javax.persistence.FlushModeType; import javax.persistence.PersistenceContextType; import javax.persistence.TransactionRequiredException; import javax.transaction.RollbackException; +import javax.transaction.Status; import javax.transaction.Synchronization; import javax.transaction.SystemException; import javax.transaction.Transaction; @@ -56,11 +58,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 +116,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 +163,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);