13

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

1 Answer 1

18

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You can take a look here stackoverflow.com/a/74512964/7237884 on the graphical representation to have a clear picture of before spring boot 3.0 and after situation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.