Skip to content

Skip adding CrudRepository when already on Spring Data 3.x#996

Merged
steve-aom-elliott merged 1 commit intomainfrom
fix/spring-data-3x-paging-sorting-guard
Apr 10, 2026
Merged

Skip adding CrudRepository when already on Spring Data 3.x#996
steve-aom-elliott merged 1 commit intomainfrom
fix/spring-data-3x-paging-sorting-guard

Conversation

@steve-aom-elliott
Copy link
Copy Markdown
Contributor

@steve-aom-elliott steve-aom-elliott commented Apr 10, 2026

Context

  • PR Add Spring Data 3.0 upgrade recipe #984 added MigratePagingAndSortingRepository to handle the Spring Data 3.0 change where PagingAndSortingRepository no longer extends CrudRepository. The recipe adds an explicit CrudRepository extends to preserve CRUD methods during migration.

  • However, as noted by @DidierLoiseau, the recipe unconditionally adds CrudRepository to any interface extending PagingAndSortingRepository — even for projects already on Spring Data 3.x where omitting CrudRepository may be an intentional design choice.

What this changes

The recipe now checks whether the classpath version of PagingAndSortingRepository still inherits from CrudRepository (i.e., Spring Data 2.x) before making changes. Since this recipe runs before the dependency version upgrade step in UpgradeSpringData_3_0, the type hierarchy on the classpath reflects the pre-migration state:

  • Spring Data 2.x: PagingAndSortingRepository extends CrudRepository → recipe fires, adds explicit CrudRepository
  • Spring Data 3.x: PagingAndSortingRepository does not extend CrudRepository → recipe is a no-op

This is a single TypeUtils.isAssignableTo check on the resolved PagingAndSortingRepository type itself.

In Spring Data 3.0, PagingAndSortingRepository no longer extends
CrudRepository by design. The recipe now checks whether the classpath
version of PagingAndSortingRepository still inherits CrudRepository
(2.x) before adding the explicit extends. This avoids unwanted changes
for projects already on Spring Data 3.x where omitting CrudRepository
is intentional.
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Apr 10, 2026
@steve-aom-elliott steve-aom-elliott merged commit ee635a2 into main Apr 10, 2026
1 check passed
@steve-aom-elliott steve-aom-elliott deleted the fix/spring-data-3x-paging-sorting-guard branch April 10, 2026 13:19
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Apr 10, 2026
@DidierLoiseau
Copy link
Copy Markdown
Contributor

Nice! That sounds like a really smart trick! (and also a good compromise to avoid searching for all usages, which could even be outside the current repository when it’s a library)

Also thanks a lot for your reactivity! 🙂

@timtebeek
Copy link
Copy Markdown
Member

Nice! That sounds like a really smart trick! (and also a good compromise to avoid searching for all usages, which could even be outside the current repository when it’s a library)

Also thanks a lot for your reactivity! 🙂

And thank you, as always, for the detailed feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants