Skip to content

AOT generated repositories are not handling NULL parameters #4304

Open

Description

@LoganWlv

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

Activity

  1. LoganWlv commented on Jul 28, 2026

    @LoganWlv
    Author

    Happy to do the PR once this is confirmed

  2. mp911de commented on Aug 3, 2026

    @mp911de
    Member

    Thanks for the report. This is a known gap. The primary idea of AOT repositories is to have exactly the query rendered as AOT variant that is going to be ran against the database. Considering nullability would require string concatenation or JPQL query parsing resulting again in code that is hard to read and hard to debug. This needs further investigation to find a better approach.

  3. LoganWlv commented on Aug 3, 2026

    @LoganWlv
    Author

    Thanks for the report. This is a known gap. The primary idea of AOT repositories is to have exactly the query rendered as AOT variant that is going to be ran against the database. Considering nullability would require string concatenation or JPQL query parsing resulting again in code that is hard to read and hard to debug. This needs further investigation to find a better approach.

    Agree that you would need JPQL parsing. I wonder if it is worth adding a point in the limitations section of here then 🤔

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions