Skip to content

Redis Repositories do not find results for custom find…ById(…) queries #2851

Closed
@soheilrahsaz

Description

@soheilrahsaz

Hello
Based on the link in documentations, https://docs.spring.io/spring-data/redis/reference/repositories/projections.html, I suppose that projections are supported with Redis repositories.
However I've written a small test application and it throws:

java.lang.UnsupportedOperationException: Query method not supported

at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.doExecute(KeyValuePartTreeQuery.java:145)
at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.execute(KeyValuePartTreeQuery.java:111)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:170)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:158)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:164)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:143)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:220)
at jdk.proxy2/jdk.proxy2.$Proxy60.findByName(Unknown Source)
at ir.co.rrr.testredis.FruitRepositoryTest.testGetProjectionFruit(FruitRepositoryTest.java:20)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

Here is my test code:

@Getter
@AllArgsConstructor
@RedisHash("Fruit")
public class Fruit {
    @Id
    private Integer id;
    @Indexed
    private String name;
    private String description;
}

public interface FruitProjection {
    String getName();
}


public interface FruitRepository extends CrudRepository<Fruit, Integer> {
    FruitProjection findProjectionById(Integer id);
    FruitProjection findByName(String name);
}

My test:

@SpringBootTest
class FruitRepositoryTest {

    @Autowired
    FruitRepository fruitRepository;

    @Test
    void testGetProjectionFruit() {
        Fruit banana = new Fruit(1, "Banana", "Yellow and long");
        Fruit saved = fruitRepository.save(banana);
        Assertions.assertThat(saved).isNotNull();

        FruitProjection projectionByName = fruitRepository.findByName("Banana");
        Assertions.assertThat(projectionByName).isNotNull();

        FruitProjection projectionById = fruitRepository.findProjectionById(1);
        Assertions.assertThat(projectionById).isNotNull();
    }
}

No other configuration or properties has been set for this project.

Using Spring boot 3.2.2.

Notes:

  1. Both findByName and findProjectionById throw exception
  2. Event without an indexed column (@Indexed), findProjectionById throws an excpetion.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions