You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems data-jdbc query derivation does not work for simple domain primitives accompanied by Reading/WritingConverters, e.g. something like
public record CustomerRef(String value) {
/** A Spring Data reading converter for {@link CustomerRef} */
@ReadingConverter
public class StringToCustomerRefConverter implements Converter<String, CustomerRef> {
@Override
public CustomerRef convert(String source) {
return new CustomerRef(source);
}
}
/** A Spring Data writing converter for {@link String} */
@WritingConverter
public class CustomerRefToStringConverter implements Converter<CustomerRef, String> {
@Override
public String convert(CustomerRef source) {
return source.value();
}
}
}
Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.Optional com.github.manosbatsis.primitive4j.sample.mvcjdbc.customer.CustomerRepository.findOneByRef(com.github.manosbatsis.primitive4j.sample.mvcjdbc.customer.CustomerRef); Reason: Cannot query by nested entity: ref
at org.springframework.data.repository.query.QueryCreationException.create(QueryCreationException.java:101) ~[spring-data-commons-3.4.3.jar:3.4.3]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:120) ~[spring-data-commons-3.4.3.jar:3.4.3]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.mapMethodsToQuery(QueryExecutorMethodInterceptor.java:104) ~[spring-data-commons-3.4.3.jar:3.4.3]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$new$0(QueryExecutorMethodInterceptor.java:92) ~[spring-data-commons-3.4.3.jar:3.4.3]
at java.base/java.util.Optional.map(Optional.java:260) ~[na:na]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.<init>(QueryExecutorMethodInterceptor.java:92) ~[spring-data-commons-3.4.3.jar:3.4.3]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:440) ~[spring-data-commons-3.4.3.jar:3.4.3]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$4(RepositoryFactoryBeanSupport.java:350) ~[spring-data-commons-3.4.3.jar:3.4.3]
at org.springframework.data.util.Lazy.getNullable(Lazy.java:135) ~[spring-data-commons-3.4.3.jar:3.4.3]
at org.springframework.data.util.Lazy.get(Lazy.java:113) ~[spring-data-commons-3.4.3.jar:3.4.3]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:356) ~[spring-data-commons-3.4.3.jar:3.4.3]
at org.springframework.data.jdbc.repository.support.JdbcRepositoryFactoryBean.afterPropertiesSet(JdbcRepositoryFactoryBean.java:198) ~[spring-data-jdbc-3.4.3.jar:3.4.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1859) ~[spring-beans-6.2.3.jar:6.2.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1808) ~[spring-beans-6.2.3.jar:6.2.3]
... 125 common frames omitted
Caused by: java.lang.IllegalArgumentException: Cannot query by nested entity: ref
at org.springframework.data.jdbc.repository.query.JdbcQueryCreator.validateProperty(JdbcQueryCreator.java:151) ~[spring-data-jdbc-3.4.3.jar:3.4.3]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.data.jdbc.repository.query.JdbcQueryCreator.validate(JdbcQueryCreator.java:130) ~[spring-data-jdbc-3.4.3.jar:3.4.3]
at org.springframework.data.jdbc.repository.query.PartTreeJdbcQuery.<init>(PartTreeJdbcQuery.java:114) ~[spring-data-jdbc-3.4.3.jar:3.4.3]
at org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JdbcQueryLookupStrategy.java:127) ~[spring-data-jdbc-3.4.3.jar:3.4.3]
at org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JdbcQueryLookupStrategy.java:257) ~[spring-data-jdbc-3.4.3.jar:3.4.3]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:116) ~[spring-data-commons-3.4.3.jar:3.4.3]
... 137 common frames omitted
The text was updated successfully, but these errors were encountered:
manosbatsis
changed the title
Query derivation not working for simple value object using Reading/WritingConverter
Query derivation not working for simple domain primitive with Reading/WritingConverter
May 16, 2025
A first test indicate that there is a two fold error here: the arguments converter doesn't get considered when validating the argument and also not when constructing the select.
This might be related to #1828 or at least its fix, which involves some refactoring of the conversion mechanics, which turn out to be duplicated between derived and other queries.
Uh oh!
There was an error while loading. Please reload this page.
It seems data-jdbc query derivation does not work for simple domain primitives accompanied by Reading/WritingConverters, e.g. something like
Trying to use the above like:
results to
The text was updated successfully, but these errors were encountered: