如何在JPA 2.0和eclipselink 2.3.1环境中设置autocommit false。 目前我从eclipselink会话中获取jdbc连接,然后在jdbc连接中设置auto commit false。还有其他方法可以在jpa中设置autocommit false。
JpaEntityManager jpaEntityManager = JpaHelper.getEntityManager(em);
AbstractSession session = (AbstractSession) jpaEntityManager.getActiveSession();
UnitOfWork unitOfWork = (UnitOfWork) jpaEntityManager.getActiveSession();
final Accessor accessor;
if (session.isInTransaction() || session.isExclusiveIsolatedClientSession()) {
accessor = session.getAccessor();
} else {
unitOfWork.beginEarlyTransaction();
accessor = session.getAccessor();
accessor.incrementCallCount(unitOfWork.getParent());
accessor.decrementCallCount();
}
java.sql.Connection connection = accessor.getConnection();
connection.setAutoCommit(false);