Skip to content

Support Set return types in MongoDB AOT repositories.#5227

Open
maryantocinn wants to merge 1 commit into
spring-projects:mainfrom
maryantocinn:issue/5225
Open

Support Set return types in MongoDB AOT repositories.#5227
maryantocinn wants to merge 1 commit into
spring-projects:mainfrom
maryantocinn:issue/5225

Conversation

@maryantocinn

Copy link
Copy Markdown
  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

Summary

Fixes AOT-generated repository implementations for query methods returning Set<T>.

ExecutableFindOperation.TerminatingResults#all() returns a List<T>. Previously, the generated method returned that value directly even when the repository method declared a Set<T>, causing the generated source to fail compilation because List<T> cannot be converted to Set<T>.

The generated code now uses DefaultConversionService to adapt the result to the declared Set return type. This applies to both entity and projection query results.

Related issue

Closes #5225

Test plan

  • Added a generated-code unit test verifying that Set return types use DefaultConversionService.

  • Added integration tests for derived queries returning sets of entities and projections.

  • Verified the original reproducer compiles its generated AOT sources against the fixed snapshot.

  • Ran:

    ./mvnw -pl spring-data-mongodb -Dtest=MongoRepositoryContributorTests,QueryMethodContributionUnitTests test

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.springframework.data.mongodb.repository.aot.QueryMethodContributionUnitTests
[INFO] Tests run: 34, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.937 s -- in org.springframework.data.mongodb.repository.aot.QueryMethodContributionUnitTests
[INFO] Running org.springframework.data.mongodb.repository.aot.MongoRepositoryContributorTests
[INFO] Tests run: 88, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 22.16 s -- in org.springframework.data.mongodb.repository.aot.MongoRepositoryContributorTests
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 122, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:01 min
[INFO] Finished at: 2026-07-21T15:43:51+07:00
[INFO] ------------------------------------------------------------------------
[INFO] 13 goals, 13 executed

Closes spring-projects#5225

Signed-off-by: Maryanto <54889592+maryantocinn@users.noreply.github.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AOT-generated repository fails to compile for query methods returning Set

2 participants