UserTransaction utx = null; try { EntityManager em = (EntityManager) (new InitialContext()).lookup( "java:comp/env/persistence/em" ); utx = (UserTransaction) (new InitialContext()).lookup( "java:comp/UserTransaction" ); utx.begin(); em.persist( entity1 ); em.merge( entity2 ); em.find( MyEntity.class, id ); utx.commit(); } catch( Exception ex ) { try { utx.rollback(); } catch( Exception e ) {/*ok*/} throw new RuntimeException( ex ); }