1、背景
项目springBoot升级到2.3.12时,发现在跑单元测试、feature用例报javax.persistence.TransactionRequiredException相关异常。
2、原因
springBoot升级2(2.3.12)大版本以后,关联所依赖的hiberante来到了hibernate5(5.4.32),其中对事务的处理做如下处理:
升级后此处将原有的配置判断去掉了,只保留了!isTransactionInprogress(),那么在update/delete时需要手动添加事务。
3、解决方案:
配置文件中手动添加如下配置开启自动提交事务:spring.jpa.properties.hibernate.allow_update_update_outside_transaction=true