Filippo De Angelis
Filippo De Angelis

Reputation: 331

Why doesn't JpaRepository have a saveAll method in Spring Data Jpa?

I'm extending JpaRepository in my code and I can't use the saveAll method even though it is in CrudRepository, which is extended by PagingAndSortingRepository, which is in turn extended by JpaRepository.

When I try to use the method as repository.saveAll(someIterable) my IDE can't find it, and if I try to override it in my repository interface as below I still get an error saying that the method doesn't override a method from a superclass.

@Override
Iterable<MyEntity> saveAll(Iterable<MyEntity> d);

Trying to compile obviously gives a compilation error. Anybody knows why?

Upvotes: 4

Views: 8921

Answers (2)

Matt
Matt

Reputation: 3190

saveAll() was not included in v1 of spring-data-jpa and didn't make its way into Spring Boot until March 2018 with the 2.0.0 release. Check your dependencies; you're likely using an older version.

Upvotes: 4

Wim Deblauwe
Wim Deblauwe

Reputation: 26868

JpaRepository overrides the saveAll() method to return a List instead of an Iterable:

In CrudRepository:

<S extends T> Iterable<S> saveAll(Iterable<S> var1);

In JpaRepository:

<S extends T> List<S> saveAll(Iterable<S> entities);

Upvotes: 0

Related Questions