Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Query derivation not working for simple domain primitive with Reading/WritingConverter #2059

Copy link
Copy link
Open
@manosbatsis

Description

@manosbatsis
Issue body actions

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();
        }
    }
}

Trying to use the above like:

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Customer {
    @Id
    private UUID id;
    @Valid
    private CustomerRef ref;
    private String name;
}

@Repository
public interface CustomerRepository extends CrudRepository<Customer, UUID> {

    Optional<Customer> findOneByRef(CustomerRef ref);
}

results to

    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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.