我在 JBoss-EAP 7.2.6 中有一个可能长时间运行的事务,我需要在几个步骤中提交。
我了解 MariaDB 没有嵌套的但链式事务。这是我对它应该如何工作的想法:
public class MyEntityManager implements IMyEntityManager {
@PersistenceContext(unitName = "org.x.y.z")
protected EntityManager em;
@Transactional(timeout = 900) // 15 minutes
public void doTransaction(MyEntity me) {
// Spring has a misfeature that @Transactional only applies when called from the outside.
// Calling through an external reference works around this shortcoming. :-(
MyEntityManager self = this;
self.persist(me);
publish(me.id); // Pseudocode, my read-only client eagerly waiting for id.
// Fill me with more data
self.flush();
// Fill me with more data
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
private void persist(MyEntity me) {
em.persist(me);
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
private void flush() {
em.flush();
}
}
我试图去NESTED
,并将驱动程序从 2.4.3 升级到 2.5.4 无济于事。
如何让这样的场景与 InnoDB 一起工作?我愿意自己发布一个低级别COMMIT AND CHAIN
,因为在@Spring/Hibernate 中似乎没有这样做的 API。
我试过
em.createNativeQuery("COMMIT AND CHAIN").executeUpdate();
但这导致
XAER_RMFAIL: The command cannot be executed when global transaction is in the ACTIVE state
尽管
em.unwrap(Session.class).createSQLQuery("COMMIT AND CHAIN").executeUpdate();
导致
GenericJDBCException: could not execute statement