Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
AbstractGenericDao.findAll(Iterable<ID>) unusable FIX #621
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieu-lavigne committed Jan 12, 2018
1 parent e226c5a commit 12d830b
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.oasp.module.jpa.dataaccess.base;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.EntityManager;
Expand All @@ -10,6 +12,7 @@
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import net.sf.mmm.util.entity.api.PersistenceEntity;
Expand Down Expand Up @@ -171,13 +174,26 @@ public List<E> findAll(Iterable<ID> ids) {
CriteriaQuery<E> query = builder.createQuery(getEntityClass());
Root<E> root = query.from(getEntityClass());
query.select(root);
query.where(root.get("id").in(ids));
query.where(root.get("id").in(toCollection(ids)));
TypedQuery<E> typedQuery = getEntityManager().createQuery(query);
List<E> resultList = typedQuery.getResultList();
LOG.debug("Query for selection of {} objects returned {} hit(s).", getEntityName(), resultList.size());
return resultList;
}

/**
* @param ids sequence of id
* @return a collection of these ids to use {@link Predicate#in(Collection)} for instance
*/
protected Collection<ID> toCollection(Iterable<ID> ids) {

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

@Override
public void delete(ID id) {

Expand Down

0 comments on commit 12d830b

Please sign in to comment.