Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
soheilrahsaz opened this issue Feb 17, 2024 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@soheilrahsaz
Copy link

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.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 17, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 20, 2024
@mp911de mp911de self-assigned this Feb 20, 2024
@mp911de
Copy link
Member

mp911de commented Feb 20, 2024

There are two issues. First, KeyValuePartTreeQuery doesn't allow queries that return a type different than the domain type, see spring-projects/spring-data-keyvalue#563. Secondly, the query by ID falls back to an index search.

The projection issue needs to be addressed in Spring Data KeyValue. I'm changing this ticket to fall back to by-id queries if the query uses a by-id constraint.

@mp911de mp911de changed the title Redis Repositories with projections throws Query method not supported Redis Repositories do not find results for custom find…ById(…) queries Feb 20, 2024
@mp911de mp911de added this to the 3.1.10 (2023.0.10) milestone Feb 20, 2024
christophstrobl pushed a commit that referenced this issue Feb 23, 2024
See: #2851
Original Pull Request: #2854
christophstrobl pushed a commit that referenced this issue Feb 23, 2024
christophstrobl pushed a commit that referenced this issue Feb 23, 2024
See: #2851
Original Pull Request: #2854
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants