【发布时间】:2017-11-14 17:00:57
【问题描述】:
我对 Springs DB-Transaction 处理有一个奇怪的行为,我无法理解。
给定以下代码:
@Transactional
public void saveDocumentToDB() {
dbService.addNewEntity('123', 'helloWorld');
DbEntity dbEntity = dbService.getEntityByID('someId');
throw new RuntimeException();
}
其中dbService 是一些@Service-class,可以访问JPA-CrudRepository。
我的问题:getEntityByID-Method 反过来调用自动生成的存储库对象上的方法提交事务,从而将第一个“添加”调用写入数据库。
没有这个调用,事务会很好地回滚...
您对如何使自动生成的 CRUD 方法也尊重事务有任何建议吗?
【问题讨论】:
标签: java spring hibernate transactions spring-data-jpa