|
33 | 33 | import javax.persistence.TypedQuery;
|
34 | 34 | import javax.persistence.criteria.CriteriaBuilder;
|
35 | 35 | import javax.persistence.criteria.CriteriaQuery;
|
36 |
| -import javax.persistence.criteria.Order; |
37 | 36 | import javax.persistence.criteria.ParameterExpression;
|
38 | 37 | import javax.persistence.criteria.Path;
|
39 | 38 | import javax.persistence.criteria.Predicate;
|
|
77 | 76 | * @author Jesse Wouters
|
78 | 77 | * @author Greg Turnquist
|
79 | 78 | * @author Yanming Zhou
|
| 79 | + * @author Ernst-Jan van der Laan |
80 | 80 | */
|
81 | 81 | @Repository
|
82 | 82 | @Transactional(readOnly = true)
|
@@ -222,13 +222,22 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) {
|
222 | 222 | return;
|
223 | 223 | }
|
224 | 224 |
|
225 |
| - String queryString = String.format(DELETE_ALL_QUERY_BY_ID_STRING, entityInformation.getEntityName(), |
226 |
| - entityInformation.getIdAttribute().getName()); |
| 225 | + if (entityInformation.hasCompositeId()) { |
| 226 | + // XXX Hibernate just creates an empty Entity when doing the getById. |
| 227 | + // Others might do a select right away causing a big performance penalty. |
| 228 | + // See JavaDoc for getById. |
| 229 | + List<T> entities = new ArrayList<>(); |
| 230 | + ids.forEach(id -> entities.add(getById(id))); |
| 231 | + deleteAllInBatch(entities); |
| 232 | + } else { |
| 233 | + String queryString = String.format(DELETE_ALL_QUERY_BY_ID_STRING, entityInformation.getEntityName(), |
| 234 | + entityInformation.getIdAttribute().getName()); |
227 | 235 |
|
228 |
| - Query query = em.createQuery(queryString); |
229 |
| - query.setParameter("ids", ids); |
| 236 | + Query query = em.createQuery(queryString); |
| 237 | + query.setParameter("ids", ids); |
230 | 238 |
|
231 |
| - query.executeUpdate(); |
| 239 | + query.executeUpdate(); |
| 240 | + } |
232 | 241 | }
|
233 | 242 |
|
234 | 243 | /*
|
@@ -313,8 +322,6 @@ public Optional<T> findById(ID id) {
|
313 | 322 | /**
|
314 | 323 | * Returns {@link QueryHints} with the query hints based on the current {@link CrudMethodMetadata} and potential
|
315 | 324 | * {@link EntityGraph} information.
|
316 |
| - * |
317 |
| - * @return |
318 | 325 | */
|
319 | 326 | protected QueryHints getQueryHints() {
|
320 | 327 | return metadata == null ? NoHints.INSTANCE : DefaultQueryHints.of(entityInformation, metadata);
|
@@ -552,8 +559,7 @@ public <S extends T> List<S> findAll(Example<S> example) {
|
552 | 559 | */
|
553 | 560 | @Override
|
554 | 561 | public <S extends T> List<S> findAll(Example<S> example, Sort sort) {
|
555 |
| - return getQuery(new ExampleSpecification<S>(example, escapeCharacter), example.getProbeType(), sort) |
556 |
| - .getResultList(); |
| 562 | + return getQuery(new ExampleSpecification<S>(example, escapeCharacter), example.getProbeType(), sort).getResultList(); |
557 | 563 | }
|
558 | 564 |
|
559 | 565 | /*
|
|
0 commit comments