Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.