我有:
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class HalloEjb implements HalloEjbLocal {
@PersistenceUnit(unitName = "testPersistenceUnitBMTHibernate")
public EntityManagerFactory entityManagerFactory;
...
}
在上面的bean中,我有一个代码:
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
entityManager.getTransaction().commit();
当应用程序从休眠实体提供程序开始时,我知道在CMT bean中它不能成为事务-对我来说这很明显,我明白以下警告:
You cannot commit during a managed transaction
但是当同一应用程序以eclipselink实体提供程序启动时,不会发生错误:
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class HalloEjb implements HalloEjbLocal {
@PersistenceUnit(unitName = "testPersistenceUnitBMTEclipseLink")
public EntityManagerFactory entityManagerFactory;
...
}
在上面的bean中,我有一个代码:
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
entityManager.getTransaction().commit();
我的问题是:为什么使用Hibernate我们已经预料到了错误,因为不允许在CMT托管bean中使用开始事务,但是为什么在EclipseLink中可以在CMT托管bean中使用commit?