我找到了解决方案!
显然,Spring无法拦截对事务方法的内部方法调用。因此,我取出了调用事务方法的方法,并将其放入一个单独的类中,并且回滚效果很好。下面是该修复程序的粗略示例。
public class Foo { public void insertRecords(List<Record> records){ Service myService = new Service(); for (Record record : records){ myService.insertIntoAAndB(record); } }}public class Service { MyDAO dao; @Transactional (rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) public void insertIntoAAndB(Record record){ insertIntoA(record); insertIntoB(record); } @Transactional(propagation = Propagation.REQUIRED) public void insertIntoA(Record record){ dao.insertIntoA(record); } @Transactional(propagation = Propagation.REQUIRED) public void insertIntoB(Record record){ dao.insertIntoB(record); } public void setMyDAO(final MyDAO dao) { this.dao = dao; }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)