JPA eclipselink禁用自动提交

时间:2015-07-24 06:32:06

标签: java jpa eclipselink

如何在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);

0 个答案:

没有答案