8
仅标记为回滚的事务:如何找到原因
我在@Transactional方法中提交事务时遇到问题: methodA() { methodB() } @Transactional methodB() { ... em.persist(); ... em.flush(); log("OK"); } 当我从methodA()调用methodB()时,该方法成功通过,并且我可以在日志中看到“确定”。但后来我明白了 Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:521) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393) …