We use Spring Data JPA for our data access framework and generally we use JpaRepository to create our repos, which is a really handy way of doing it. Spring uses the SimpleJpaRepository for its implementation and it does have a save that allows an Iterable, but if you look at the code it just loops over the entities and calls the save method on each one.
So, if we want to save, or update, in a batch we need to use something else. Luckily, Spring JDBC has a pretty handy way of doing it and you can add custom repos to your repository interface.
Like so:
To see the collection util that splits out our collection into batches see Split a Java List Into a List of Sublists
Both Spring data jpa and jdbc template exist, it it safe?
ReplyDelete