The JpaRepository interface provides a saveAll() method to perform bulk inserts of multiple entities. The method accepts an iterable of entities and inserts them all into the database in a single transaction.
Here's an example:
//Assuming entity name is Product
List<Product> productList = new ArrayList<>();
productList.add(new Product("Product1", 10));
productList.add(new Product("Product2", 20));
productList.add(new Product("Product3", 30));
productRepository.saveAll(productList);
This will insert all three Product entities into the database in a single transaction.
Asked: 2023-07-04 14:28:08 +0000
Seen: 9 times
Last updated: Jul 04 '23