oasp / oasp4j

The Open Application Standard Platform for Java
Apache License 2.0
60 stars 303 forks source link

AbstractGenericDao.findAll(Iterable<ID>) unusable #621

Closed mathieu-lavigne closed 6 years ago

mathieu-lavigne commented 6 years ago

Hi Team,

We are trying to use the findAll(Iterable) in the AbstractGenericDao class in jpa module but it seems it cannot work because of this line of code :

query.where(root.get("id").in(ids);

in method accepts an array of ID and if we call it using a Iterable it will be treated as if we want to cast Iterable to ID.

These few lines of codes are needed to convert ids into array of ID :

    final List<ID> idsList = new ArrayList<>();
    for (final ID id : ids) {
      idsList.add(id);
    }

and then we can call :

query.where(root.get("id").in(idsList.toArray()));

I will create a PR to fix it if it seems okay for you.

hohwille commented 6 years ago

Thanks for the finding. What a pitty. We should also consider this for a solution: https://github.com/spring-projects/spring-data-jpa/blob/master/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java#L313

mathieu-lavigne commented 6 years ago

Hi @hohwille maybe nobody use this method :)

I tried to adapt Spring's method but they do not use the same internal objects. Moreover they use findById in a loop, I don't know if this is very efficient compared to the single "select in" query already used in devon.

I send you my PR as-this so you can adapt it.