Skip to content

Kotlin value class as primary key causes exception when used with findAll methods in Spring Data JDBC 4 #2225

@edwardmp

Description

@edwardmp

I have noticed after updating to Spring Boot 4.0.1, findAllById queries no longer work properly with value classes like before.

Here's a reproducible example (run CarRepositoryTests): https://github.com/edwardmp/spring-data-jdbc-value-class-bug

So far the issue seems limited to queries where multiple value class instances are passed (like findAllById), but not 100% sure if this is the only case.
Runtime it leads to the following exception:

PreparedStatementCallback; bad SQL grammar [SELECT "car"."id" AS "id", "car"."name" AS "name" FROM "car" WHERE "car"."id" IN ((?), (?))]
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT "car"."id" AS "id", "car"."name" AS "name" FROM "car" WHERE "car"."id" IN ((?), (?))]
	at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:134)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:102)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:111)
	at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1548)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:688)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:731)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:751)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:803)

When just passing a single value class param (like findById), everything works fine though.
I noticed while debugging the WritingConverter is not called, which probably has something do with it. In the working case with a single value class param, the converter is called.

At the point the exception is thrown, I can see the class is the value class, not the underlying boxed type.

I'm not sure yet why this happens, but this was working properly before Spring Boot 4.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions