Skip to content

fix(aot): handle null equality parameters in derived repository queries - #4309

Open
arimu1 wants to merge 2 commits into
spring-projects:mainfrom
arimu1:GH-4304-aot-null-parameters
Open

fix(aot): handle null equality parameters in derived repository queries#4309
arimu1 wants to merge 2 commits into
spring-projects:mainfrom
arimu1:GH-4304-aot-null-parameters

Conversation

@arimu1

@arimu1 arimu1 commented Aug 5, 2026

Copy link
Copy Markdown

Overview

Fixes #4304

AOT repository generation materializes a single JPQL string for derived query methods. Equality predicates were always rendered as path = :param, so a null argument never matched rows with SQL NULL (runtime PartTree rewrites those cases to IS NULL / IS NOT NULL per invocation).

This change renders null-safe equality for AOT PartTree queries:

(path = :p OR path IS NULL AND :p IS NULL)          -- SIMPLE_PROPERTY
(path != :p OR path IS NOT NULL AND :p IS NULL)     -- NEGATING_SIMPLE_PROPERTY

That keeps one static, readable query (aligned with AOT goals) while matching runtime null/non-null semantics for derived finders.

Scope notes

  • Applies to derived (PartTree) methods generated by AOT.
  • Declared @Query / native queries are unchanged and keep the query as written (same as the non-AOT runtime path; null → IS NULL rewriting is a PartTree feature).
  • Binary/array and LOB parameter types skip the dual-bind form (JDBC drivers such as HSQLDB reject dual use of the same bind marker for = and IS NULL on byte[] / BLOB).

Checklist

  • 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).

Tests

Temurin 21:

./mvnw -pl spring-data-jpa test \
  -Dtest=JpaQueryCreatorTests,JpaRepositoryContributorIntegrationTests,JpaRepositoryMetadataIntegrationTests,AotUserRepositoryTests,QueriesFactoryUnitTests
  • JpaQueryCreatorTests (null-safe JPQL rendering)
  • JpaRepositoryContributorIntegrationTests (null + non-null derived equality / not-equality)
  • JpaRepositoryMetadataIntegrationTests (metadata query string)
  • AotUserRepositoryTests284/284 (incl. binary data still OK)

DCO: Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>

mp911de and others added 2 commits August 5, 2026 16:11
AOT materializes a single JPQL string for derived methods and previously
always rendered SIMPLE_PROPERTY as path = :param. At runtime, PartTree
rewrites null arguments to IS NULL / IS NOT NULL.

Render null-safe equality predicates for AOT PartTree queries so fixed
queries match runtime semantics for null and non-null arguments.

Fixes spring-projects#4304

Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
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 repositories are not handling NULL parameters

3 participants