Reputation: 91
I have a basic SpringBoot app with repositories that extends JpaRepository and services in which repos are injected. I'm trying to batch insert by looking here: https://vladmihalcea.com/how-to-batch-insert-and-update-statements-with-hibernate/
When trying to open a transaction, I get an error Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead
I mention that I have @EnableTransactionManagement
so that's why I can't create transactions by myself. What are my options?
Upvotes: 0
Views: 1283
Reputation: 691635
The post shows that you need to split the large batch into several smaller transactions. Whether you open and commit/rollback them yourself, programmatically, or let Spring do that for you, doesn't change the idea.
So just let Spring open and commit/rollback them for you. Have a service A call a service B in a loop, where each call to B executes a slice of the batch, in a new, declarative, transaction.
Upvotes: 1