spring-projects / spring-projects/spring-data-jpa
AOT generated repositories are not handling NULL parameters
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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