spring-projects / spring-projects/spring-data-jpa

AOT generated repositories are not handling NULL parameters

Open
#4,304 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
Java
Stars
3.3k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

In our Spring Boot project, we do use spring.aot.repositories.enabled.
Let's consider this repository:

public interface ThingRepository extends JpaRepository<Thing, UUID> {
    @Query("SELECT t FROM Thing t WHERE t.groupId = :groupId")
    List<Thing> findByGroupId(UUID groupId);
}

where groupId is nullable.

The AOT-generated method will be:

public List<Thing> findByGroupId(UUID groupId) {
    String var2 = "SELECT t FROM Thing t WHERE t.groupId = :groupId";
    Query var3 = this.entityManager.createQuery(var2);
    var3.setParameter("groupId", groupId);
    return var3.getResultList();
}

It works until groupId is null; the final query does not use IS NULL.

I didn't try to annotate the field @Nullable as I don't expect such behavior to be driven by those annotations.

Spring Boot: 4.1.0
MacOs: 26.5.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported repository with a nullable UUID groupId and spring.aot.repositories.enabled enabled. Inspect the AOT-generated findByGroupId method and its parameter handling, then verify that the generated query behaves correctly when groupId is null and that the existing non-null case still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.