|
15 | 15 | */
|
16 | 16 | package org.springframework.data.jpa.repository.support;
|
17 | 17 |
|
| 18 | +import static org.springframework.data.jpa.repository.query.QueryUtils.*; |
| 19 | + |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.Collection; |
| 22 | +import java.util.Collections; |
| 23 | +import java.util.HashMap; |
| 24 | +import java.util.List; |
| 25 | +import java.util.Map; |
| 26 | +import java.util.Optional; |
| 27 | +import java.util.function.Function; |
| 28 | +import java.util.stream.Collectors; |
| 29 | +import java.util.stream.StreamSupport; |
| 30 | + |
| 31 | +import javax.persistence.EntityManager; |
| 32 | +import javax.persistence.LockModeType; |
| 33 | +import javax.persistence.NoResultException; |
| 34 | +import javax.persistence.Parameter; |
| 35 | +import javax.persistence.Query; |
| 36 | +import javax.persistence.TypedQuery; |
| 37 | +import javax.persistence.criteria.CriteriaBuilder; |
| 38 | +import javax.persistence.criteria.CriteriaQuery; |
| 39 | +import javax.persistence.criteria.ParameterExpression; |
| 40 | +import javax.persistence.criteria.Path; |
| 41 | +import javax.persistence.criteria.Predicate; |
| 42 | +import javax.persistence.criteria.Root; |
| 43 | + |
18 | 44 | import org.springframework.dao.EmptyResultDataAccessException;
|
19 | 45 | import org.springframework.data.domain.Example;
|
20 | 46 | import org.springframework.data.domain.Page;
|
|
37 | 63 | import org.springframework.transaction.annotation.Transactional;
|
38 | 64 | import org.springframework.util.Assert;
|
39 | 65 |
|
40 |
| -import javax.persistence.EntityManager; |
41 |
| -import javax.persistence.LockModeType; |
42 |
| -import javax.persistence.NoResultException; |
43 |
| -import javax.persistence.Parameter; |
44 |
| -import javax.persistence.Query; |
45 |
| -import javax.persistence.TypedQuery; |
46 |
| -import javax.persistence.criteria.CriteriaBuilder; |
47 |
| -import javax.persistence.criteria.CriteriaQuery; |
48 |
| -import javax.persistence.criteria.ParameterExpression; |
49 |
| -import javax.persistence.criteria.Path; |
50 |
| -import javax.persistence.criteria.Predicate; |
51 |
| -import javax.persistence.criteria.Root; |
52 |
| -import java.util.ArrayList; |
53 |
| -import java.util.Collection; |
54 |
| -import java.util.Collections; |
55 |
| -import java.util.HashMap; |
56 |
| -import java.util.List; |
57 |
| -import java.util.Map; |
58 |
| -import java.util.Optional; |
59 |
| -import java.util.function.Function; |
60 |
| - |
61 |
| -import static org.springframework.data.jpa.repository.query.QueryUtils.*; |
62 |
| - |
63 | 66 | /**
|
64 | 67 | * Default implementation of the {@link org.springframework.data.repository.CrudRepository} interface. This will offer
|
65 | 68 | * you a more sophisticated interface than the plain {@link EntityManager} .
|
@@ -237,7 +240,16 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) {
|
237 | 240 | entityInformation.getIdAttribute().getName());
|
238 | 241 |
|
239 | 242 | Query query = em.createQuery(queryString);
|
240 |
| - query.setParameter("ids", ids); |
| 243 | + /** |
| 244 | + * Some JPA providers require {@code ids} to be a {@link Collection} so we must convert if it's not already. |
| 245 | + */ |
| 246 | + if (Collection.class.isInstance(ids)) { |
| 247 | + query.setParameter("ids", ids); |
| 248 | + } else { |
| 249 | + Collection<ID> idsCollection = StreamSupport.stream(ids.spliterator(), false) |
| 250 | + .collect(Collectors.toCollection(ArrayList::new)); |
| 251 | + query.setParameter("ids", idsCollection); |
| 252 | + } |
241 | 253 |
|
242 | 254 | query.executeUpdate();
|
243 | 255 | }
|
@@ -325,7 +337,6 @@ public Optional<T> findById(ID id) {
|
325 | 337 | /**
|
326 | 338 | * Returns {@link QueryHints} with the query hints based on the current {@link CrudMethodMetadata} and potential
|
327 | 339 | * {@link EntityGraph} information.
|
328 |
| - * |
329 | 340 | */
|
330 | 341 | protected QueryHints getQueryHints() {
|
331 | 342 | return metadata == null ? NoHints.INSTANCE : DefaultQueryHints.of(entityInformation, metadata);
|
@@ -563,8 +574,7 @@ public <S extends T> List<S> findAll(Example<S> example) {
|
563 | 574 | */
|
564 | 575 | @Override
|
565 | 576 | public <S extends T> List<S> findAll(Example<S> example, Sort sort) {
|
566 |
| - return getQuery(new ExampleSpecification<>(example, escapeCharacter), example.getProbeType(), sort) |
567 |
| - .getResultList(); |
| 577 | + return getQuery(new ExampleSpecification<>(example, escapeCharacter), example.getProbeType(), sort).getResultList(); |
568 | 578 | }
|
569 | 579 |
|
570 | 580 | /*
|
|
0 commit comments