|
1 | 1 | package io.oasp.module.jpa.dataaccess.base; |
2 | 2 |
|
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.Collection; |
3 | 5 | import java.util.List; |
4 | 6 |
|
5 | 7 | import javax.persistence.EntityManager; |
|
10 | 12 | import javax.persistence.TypedQuery; |
11 | 13 | import javax.persistence.criteria.CriteriaBuilder; |
12 | 14 | import javax.persistence.criteria.CriteriaQuery; |
| 15 | +import javax.persistence.criteria.Predicate; |
13 | 16 | import javax.persistence.criteria.Root; |
14 | 17 |
|
15 | 18 | import net.sf.mmm.util.entity.api.PersistenceEntity; |
@@ -171,13 +174,26 @@ public List<E> findAll(Iterable<ID> ids) { |
171 | 174 | CriteriaQuery<E> query = builder.createQuery(getEntityClass()); |
172 | 175 | Root<E> root = query.from(getEntityClass()); |
173 | 176 | query.select(root); |
174 | | - query.where(root.get("id").in(ids)); |
| 177 | + query.where(root.get("id").in(toCollection(ids))); |
175 | 178 | TypedQuery<E> typedQuery = getEntityManager().createQuery(query); |
176 | 179 | List<E> resultList = typedQuery.getResultList(); |
177 | 180 | LOG.debug("Query for selection of {} objects returned {} hit(s).", getEntityName(), resultList.size()); |
178 | 181 | return resultList; |
179 | 182 | } |
180 | 183 |
|
| 184 | + /** |
| 185 | + * @param ids sequence of id |
| 186 | + * @return a collection of these ids to use {@link Predicate#in(Collection)} for instance |
| 187 | + */ |
| 188 | + protected Collection<ID> toCollection(Iterable<ID> ids) { |
| 189 | + |
| 190 | + final Collection<ID> idsList = new ArrayList<>(); |
| 191 | + for (final ID id : ids) { |
| 192 | + idsList.add(id); |
| 193 | + } |
| 194 | + return idsList; |
| 195 | + } |
| 196 | + |
181 | 197 | @Override |
182 | 198 | public void delete(ID id) { |
183 | 199 |
|
|
0 commit comments