0

I have an entity that follows this structure:

name: String(not null, unique),
value: Integer(not null)
id: Long(generated, not null, unique)

I have a list of entities(List<>), and I want to save them to a table or update if some were already in a table, but I need an effective way to do that with some bulk/batch insert/update. Now I've tried repository.saveAll and entityManager.merge, but I get the repeated value error, as it doesn't update the values that're already in a table. What should I do?

1 Answers1

0

Please refer to this topic:

How to do bulk (multi row) inserts with JpaRepository?

To get a bulk insert with Sring Boot and Spring Data JPA you need only two things:

  1. set the option spring.jpa.properties.hibernate.jdbc.batch_size to appropriate value you need (for example: 20).
  2. use saveAll() method of your repo with the list of entities prepared for inserting.