Skip to content

Emit Sort.Order separator before non-first orders in AOT generation - #2381

Closed
atirna wants to merge 1 commit into
spring-projects:mainfrom
atirna:issue/2377
Closed

Emit Sort.Order separator before non-first orders in AOT generation#2381
atirna wants to merge 1 commit into
spring-projects:mainfrom
atirna:issue/2377

Conversation

@atirna

@atirna atirna commented Sep 6, 2026

Copy link
Copy Markdown

Derived query methods with two or more static OrderBy properties produce Java from the AOT generator that does not compile, so compileAotJava fails and the app cannot build in AOT / GraalVM native mode.

Why

JdbcCodeBlocks.buildSort appended the , separator after each non-first order instead of before, so findAllByOrderByFirstNameAscLastNameDesc() generated:

Sort.by(Sort.Order.asc("firstName")Sort.Order.asc("lastName"), )

which javac rejects with ')' or ',' expected. With one static OrderBy property the loop happened to work because the trailing separator landed after the last (only) order, masking the bug. The separator now goes before each non-first order:

Sort.by(Sort.Order.asc("firstName"), Sort.Order.asc("lastName"))

Single-order emission is unchanged (findTop5ByOrderByAge and its test cover that).

Verification

  • before, on current main: ./mvnw -pl spring-data-jdbc verify -Dit.test=JdbcRepositoryContributorIntegrationTests -Dspring.profiles.active=h2: context load fails with CompilationException: Unable to compile source on the malformed Sort.by(...)
  • after: same command, Tests run: 38, Failures: 0, Errors: 0
  • the new listWithMultipleStaticOrderByProperties inserts a duplicate firstname so the second order key decides the row order, and asserts both keys' effect on the result

Fixes #2377

Derived query methods with two or more static OrderBy properties produced
invalid Java from JdbcCodeBlocks.buildSort: the separator was appended
after each non-first order, so Sort.by(order1 order2, ) failed to compile
in compileAotJava. Emit the separator before each non-first order instead.

Fixes spring-projects#2377

Signed-off-by: Atirna <288419661+atirna@users.noreply.github.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 6, 2026
schauder added a commit that referenced this pull request Sep 10, 2026
Derived query methods with two or more static OrderBy properties produced
invalid Java from JdbcCodeBlocks.buildSort: the separator was appended
after each non-first order. Emit the separator before each non-first order instead.

Closes #2377

Signed-off-by: Atirna <288419661+atirna@users.noreply.github.com>

Original pull request #2381
schauder added a commit that referenced this pull request Sep 10, 2026
Derived query methods with two or more static OrderBy properties produced
invalid Java from JdbcCodeBlocks.buildSort: the separator was appended
after each non-first order. Emit the separator before each non-first order instead.

Closes #2377

Signed-off-by: Atirna <288419661+atirna@users.noreply.github.com>

Original pull request #2381
@schauder schauder self-assigned this Sep 10, 2026
@schauder schauder added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 10, 2026
@schauder schauder added this to the 4.0.8 (2025.1.8) milestone Sep 10, 2026
@schauder

Copy link
Copy Markdown
Contributor

Thanks, for the PR. That's fixed.

@schauder schauder closed this Sep 10, 2026
schauder added a commit that referenced this pull request Sep 10, 2026
Derived query methods with two or more static OrderBy properties produced
invalid Java from JdbcCodeBlocks.buildSort: the separator was appended
after each non-first order. Emit the separator before each non-first order instead.

Closes #2377

Signed-off-by: Atirna <288419661+atirna@users.noreply.github.com>

Original pull request #2381
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AOT-generated JDBC repository source has invalid syntax for multi-property static OrderBy queries

3 participants