我得到了这段代码。我使用的弹簧引导和JPA如何处理弹簧jpa @transactional和从catch块新插入
@Transactional
public class MyClass {
public void createSomething() {
try {
saveAndFlush();
} catch (Exception e) {
// Since error has occured I want to insert this information
// into a audit table
repository.saveAndFlush();
}
}
}
现在,当异常发生时,事务回滚,因此错误表插入没有发生。
我看到
HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: null id in XXXXX entry (don't flush the Session after an exception occurs)
为了解决这个问题我试着做了错误插入在理解打上@Transactional(propagation = Propagation.REQUIRES_NEW)
,内部交易将完成与外将回滚
但我没有看到我的预期输出。
请告知
正确。这确实是一个重复 – Shiv
@阿兰干草 - 即使按照原始线程中的说明,我仍然看到相同的问题。我将其作为个别方法中的交易,并添加了一个需要新的传播 – Shiv