Open lukas-krecan opened 1 month ago
This is indeed correct behavior. Spring Data determines the target type for a conversion. new ConvertiblePair(Id.class, Long.class)
indicates that Id
values should be converted into Long
. new ConvertiblePair(Id.class, UUID.class)
imposes a conflicting declaration and only one variant can win, therefore you see various incarnations of ConversionFailedException
.
You could bypass the issue with annotating IdConverter
with @ReadingConverter
to just register converters.
The actual issue however is still present that Spring Data JDBC makes invalid assumptions regarding proper conversion in the code path that attempts to convert Id<?>
into JdbcValue
because it assumes Id
is an entity type.
We need to fix that.
IMO the issue is not about confusion about variants, the core problem is that a different converter is used. I register Id<->UUID converter, but a standard String<->UUID converter is used (type
argument of writeValue
is basically ignored).
But if I understand you correctly, annotating the converter as @ReadingConverter
would let us use the standard converters for the write path and our converter only for reading? Cool, I will try that. Thanks.
The workaround with ReadingConverter
does not work due to
Caused by: java.lang.IllegalArgumentException: Cannot query by nested entity: userId
at org.springframework.data.jdbc.repository.query.JdbcQueryCreator.validateProperty(JdbcQueryCreator.java:151)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.data.jdbc.repository.query.JdbcQueryCreator.validate(JdbcQueryCreator.java:130)
at org.springframework.data.jdbc.repository.query.PartTreeJdbcQuery.<init>(PartTreeJdbcQuery.java:114)
at org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JdbcQueryLookupStrategy.java:124)
at org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JdbcQueryLookupStrategy.java:212)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:111)
We are using Spring Data JDBC and a generic type for entity ID.
For it to work we have a custom converter (see the example below).
Our code works in Spring 3.2.5 but does not in 3.2.8 (and most likely some previous versions too). It throws
I am able to reproduce the behavior using the following code - it passes in 3.2.5 but fails in 3.2.8. In 3.2.5 it correctly calls the custom converter, in later releases it picks a wrong converter and fails.