diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 50afeee8a5c..eb6f2938cd6 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -244,7 +244,7 @@ public void deleteAllByIdInBatch(Iterable ids) { * Some JPA providers require {@code ids} to be a {@link Collection} so we must convert if it's not already. */ - if (Collection.class.isInstance(ids)) { + if (ids instanceof Collection) { query.setParameter("ids", ids); } else { Collection idsCollection = StreamSupport.stream(ids.spliterator(), false) @@ -481,12 +481,10 @@ public long delete(Specification spec) { CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); CriteriaDelete delete = builder.createCriteriaDelete(getDomainClass()); - if (spec != null) { - Predicate predicate = spec.toPredicate(delete.from(getDomainClass()), null, builder); + Predicate predicate = spec.toPredicate(delete.from(getDomainClass()), builder.createQuery(getDomainClass()), builder); - if (predicate != null) { - delete.where(predicate); - } + if (predicate != null) { + delete.where(predicate); } return this.entityManager.createQuery(delete).executeUpdate(); @@ -853,11 +851,13 @@ private TypedQuery applyRepositoryMethodMetadata(TypedQuery query) { } LockModeType type = metadata.getLockModeType(); - TypedQuery toReturn = type == null ? query : query.setLockMode(type); + if (type == null) { + query.setLockMode(type); + } - applyQueryHints(toReturn); + applyQueryHints(query); - return toReturn; + return query; } private void applyQueryHints(Query query) {