Spring Data JPA saveAll not doing batch insert
Hibernate doesn't perform insert batching with the identity identifier generator.
More info is here.
Spring Boot Appllication. Batch doesn't work in JpaRepository.saveAll method
Batch doesn't work with GenerationType.IDENTITY
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Need to use sequence.
Example:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "row_generator")
@SequenceGenerator(name = "row_generator", sequenceName = "db_generator", allocationSize = 1)
private Long id;
Bulk insert with Spring Boot and Spring Data JPA not working
Try to change your code like this:
public void process() {
PodamFactory podamFactory = new PodamFactoryImpl();
List<MyEntity> myEntities = new ArrayList<>(10000);
for(int i = 0; i < 10000; i++) {
myEntities.add(podamFactory.manufacturePojo(MyEntity.class));
}
repository.save(myEntities); // for Spring Boot prior 2.0
// repository.saveAll(myEntities); - for Spring Boot since 2.0
}
P.S. don't forget to turn on spring.jpa.show-sql
to see result
UPDATE
Please also check my another answer about bulk insert:
How to do bulk (multi row) inserts with JpaRepository?
Related Topics
How to Loop Through List of Webelements and Select One Webelement With a Condition
Regex, Remove Whitespace and All Other Characters
Kafka: Failed to Update Metadata After 60000 Ms
Spring Boot - Json Object Array to Java Array
How to Get an Http Response Body as a String
Json to Pojo With Nested Values
Jackson Polymorphism: How to Map Multiple Subtypes to the Same Class
Badpaddingexception Decrypting the Encrypted Data in Android
Adb Cannot Connect to Daemon At Tcp:5037
Iterate Through Each Digit in a Number
Spring Boot API Call With Multiple @Requestparam
Error: Could Not Find or Load Main Class in Intellij Ide
Spring Boot Controller Not Mapping
Hibernate Foreign Key Issue:Error Executing Ddl "Alter Table..."