13

I am working with Spring data Redis and have the following repository:

public interface MyClassRepository extends CrudRepository<MyClass, String> {
}

When I call findAll(Iterable< String> ids) method, correct data is returned:

final List<String> ids = Lists.newArrayList("id1", "id2");
final Iterable<MyClass> mappingIterable = mappingRepository.findAll(ids);

However, calling findAll() is not returning data, instead it returns null value against each of the id present in Redis:

final Iterable<MyClass> mappingIterable = mappingRepository.findAll();

Returns:

[null, null]

Azeem
  • 11,148
  • 4
  • 27
  • 40
Ms. Zia
  • 411
  • 3
  • 12
  • 2
    ehm ... what is the difference between those two calls? you posted the same call twice. – Stultuske Dec 19 '17 at 08:45
  • What is different between those calls. Second one not have ids List so u dont declare null return to you – Er.Er Dec 19 '17 at 09:12
  • @Stultuske Sorry, pls check now – Ms. Zia Dec 19 '17 at 09:13
  • @Er.Er Can you kindly check now and elaborate your answer little more? – Ms. Zia Dec 19 '17 at 09:19
  • I couldn't see an usage like that on [link](https://msdn.microsoft.com/tr-tr/library/fh1w7y8z%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396) i think u have to send a list in findall() – Er.Er Dec 19 '17 at 09:24
  • so then findAll(ids); shouldn't be work. it should be findAllById(ids); so something wrong :D – Er.Er Dec 19 '17 at 09:34
  • @Er.Er, Please check this one: https://docs.spring.io/autorepo/docs/spring-data-commons/1.13.0.M1/api/org/springframework/data/repository/CrudRepository.html – Ms. Zia Dec 19 '17 at 09:45
  • Are you by any chance using Mocks? I just encountered the same scenario in a JUnit test. My repository was a mock and I resolved the issue by initialising the mock to return a `Set` when the `findAll()` method was called. – Tiksi Dec 20 '17 at 03:32
  • 3
    Seems a bug in Spring Data Redis: https://jira.spring.io/browse/DATAREDIS-570 – y.luis.rojo Jul 05 '18 at 22:03
  • As of december 2018, I am having the same issue. Has anyone been able to fix? – Evdzhan Mustafa Dec 19 '18 at 11:13
  • Which version of spring, and dependencies? – TechFree Jun 11 '19 at 07:44
  • 1
    it's March 2020, the bug is still not fixed – ktcl Mar 11 '20 at 02:53

3 Answers3

0

You may try to replace a normal List with ArrayList, which will make it easier to create and update, if your project doesn't require to use just List. It may not work, but could make your work easier. Anyways, good luck!

EyVanVen
  • 1
  • 2
0

have you tried passing an empty list as parameter ? you can try:

repo.findAll(new ArrayList<>());

I suspect that you need to override findAll with no parameters yet I am not sure about that.

-1

did you try findAllById(Iterable ids) https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/CrudRepository.html#findAllById-java.lang.Iterable-

Jigar Gajjar
  • 183
  • 2
  • 12
  • This is basically the same method that works for the question author. What he wants is to get all the records, not filtering by any list of known ids. – Matvey Zhuravel Sep 19 '20 at 19:36