mengmeng
mengmeng

Reputation: 1496

Flush saveAll in JpaRepository

Since there's a saveAndFlush(), is there a way to Flush the updated entities when using saveAll()?

I'm trying to update entities by batch.

Upvotes: 6

Views: 11656

Answers (2)

Aniket Sahrawat
Aniket Sahrawat

Reputation: 12937

No need to manually call flush() after saveAll(), just create a default method. Eg of Person:

@Repository
interface PersonRepo extends JpaRepository<Person, String> {
    default List<Person> saveAllAndFlush(Iterable<Person> iterable) {
        List<Person> list = saveAll(iterable);
        flush();
        return list;
    }
}

Upvotes: 8

amseager
amseager

Reputation: 6391

No, but you can manually call saveAll() and then flush().

Upvotes: 5

Related Questions