protected void enlistExtendedEntityManagers(ComponentContext ctx) { if (isStatefulSession && (ctx.getTransaction() != null)) { JavaEETransaction j2eeTx = (JavaEETransaction) ctx.getTransaction(); SessionContextImpl sessionCtx = (SessionContextImpl) ctx; Map<EntityManagerFactory, EntityManager> entityManagerMap = sessionCtx.getExtendedEntityManagerMap(); for (Map.Entry<EntityManagerFactory, EntityManager> entry : entityManagerMap.entrySet()) { EntityManagerFactory emf = entry.getKey(); EntityManager extendedEm = entry.getValue(); EntityManager extendedEmAssociatedWithTx = j2eeTx.getExtendedEntityManager(emf); // If there's not already an EntityManager registered for // this extended EntityManagerFactory within the current tx if (extendedEmAssociatedWithTx == null) { j2eeTx.addExtendedEntityManagerMapping(emf, extendedEm); sessionCtx.setEmfRegisteredWithTx(emf, true); // Tell persistence provider to associate the extended // entity manager with the transaction. // @@@ Comment this out when joinTransaction supported on // EntityManager API. extendedEm.joinTransaction(); } } } }
@Override protected void enlistExtendedEntityManagers(ComponentContext ctx) { if (ctx.getTransaction() != null) { JavaEETransaction j2eeTx = (JavaEETransaction) ctx.getTransaction(); SessionContextImpl sessionCtx = (SessionContextImpl) ctx; Map<EntityManagerFactory, PhysicalEntityManagerWrapper> entityManagerMap = sessionCtx.getExtendedEntityManagerMap(); for (Map.Entry<EntityManagerFactory, PhysicalEntityManagerWrapper> entry : entityManagerMap.entrySet()) { EntityManagerFactory emf = entry.getKey(); PhysicalEntityManagerWrapper extendedEm = entry.getValue(); PhysicalEntityManagerWrapper extendedEmAssociatedWithTx = EntityManagerWrapper.getExtendedEntityManager(j2eeTx, emf); // If there's not already an EntityManager registered for // this extended EntityManagerFactory within the current tx if (extendedEmAssociatedWithTx == null) { j2eeTx.addExtendedEntityManagerMapping(emf, extendedEm); sessionCtx.setEmfRegisteredWithTx(emf, true); // Tell persistence provider to associate the extended // entity manager with the transaction. if(extendedEm.getSynchronizationType() == SYNCHRONIZED) { extendedEm.getEM().joinTransaction(); } } } } }