Spring Data JPA批量插入

时间:2018-01-23 16:31:24

标签: hibernate spring-boot spring-data-jpa

我有一个带有存储库的基本SpringBoot应用程序,它扩展了JpaRepository和注入了repos的服务。我试着通过查看这里批量插入:https://vladmihalcea.com/how-to-batch-insert-and-update-statements-with-hibernate/ 在尝试打开交易时,我收到错误Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead 我提到我有@EnableTransactionManagement这就是为什么我不能自己创建交易。我有什么选择?

1 个答案:

答案 0 :(得分:1)

该帖子显示您需要将大批量拆分为几个较小的交易。无论你是以编程方式打开并提交/回滚它们,还是让Spring为你做这些,都不会改变这个想法。

所以让Spring打开并为你提交/回滚它们。有一个服务A在循环中调用服务B,其中每次调用B在一个新的声明性事务中执行批处理的一部分。

相关问题