6

I have the following Spring Data JPA repository:

public interface FooRepository extends PagingAndSortingRepository<Foo, Long> {}

And after migrating to Spring Boot 3, I started getting Error messages for most standard repository methods (e.g. fooRepository.findById(id), fooRepository.save(foo), fooRepository.findAll())

I couldn't find anything related to this in the Spring Boot 3.0 Migration Guide

Gerardo Roza
  • 2,746
  • 2
  • 24
  • 33

1 Answers1

7

It seems that Spring Data 3.0 has now separated the "Sorting" repositories from the base ones (i.e. PagingAndSortingRepository and other interfaces don't extend CrudRepository anymore), and so, we have to make our repositories extend more than one framework repo interfaces, combining them as we want to.

A cause for this is that Spring Data JPA has introduced a ListCrudRepository interface now that retrieves List results instead of Iterable as the CrudRepository did (which in many cases was a pain to deal with).

So, with this unbinding, we can now choose to combine PagingAndSortingRepository with CrudRepository as was the previous behavior, or instead use it with ListCrudRepository:

public interface FooRepository extends 
  PagingAndSortingRepository<Foo, Long>,
  CrudRepository<Foo, Long> {}

All this is explained in this Spring Data Announcement post, and also in the Spring Data 3.0 docs:

Note that the various sorting repositories no longer extended their respective CRUD repository as they did in Spring Data Versions pre 3.0. Therefore, you need to extend both interfaces if you want functionality of both.

Gerardo Roza
  • 2,746
  • 2
  • 24
  • 33
  • 1
    You can take a look here https://stackoverflow.com/a/74512964/7237884 on the graphical representation to have a clear picture of before spring boot 3.0 and after situation. – Panagiotis Bougioukos Dec 23 '22 at 21:31