@ SuppressWarnings ( "unchecked" ) private EntityManager getEntityManager ( ) { if ( txDataKey == null ) { txDataKey = new StringBuilder ( "jpapef.em." ) . append ( component . getProfileSpecificationID ( ) ) . toString ( ) ; } final TransactionContext txContext = sleeTransactionManager . getTransactionContext ( ) ; // look in tx Map transactionContextData = txContext . getData ( ) ; EntityManager result = ( EntityManager ) transactionContextData . get ( txDataKey ) ; if ( result == null ) { // create using factory result = entityManagerFactory . createEntityManager ( ) ; // store in tx context data transactionContextData . put ( txDataKey , result ) ; // add a tx action to close it before tx commits // FIXME: Do we need this after-rollback action here /* final EntityManager em = result; TransactionalAction action = new TransactionalAction() { public void execute() { try { em.close(); } catch (Throwable e) { logger.error(e.getMessage(), e); } } }; txContext.getAfterRollbackActions().add(action); */ } return result ; }
Retrieves the entity manager for the current tx and the framework profile spec