Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flush saveAll in JpaRepository

Tags:

java

spring

jpa

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.

Will really be a big help!

Thank you!

like image 361
mengmeng Avatar asked Jan 25 '23 02:01

mengmeng


1 Answers

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;
    }
}
like image 57
Aniket Sahrawat Avatar answered Jan 27 '23 16:01

Aniket Sahrawat