From bed347d223589c20a7dcfa8a129cf3818b41d1f7 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 27 Jun 2013 22:17:24 +0200 Subject: [PATCH] DATAJPA-363 - Improved implementation of SimpleJpaRepository.delete(ID id). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the additional call to exists(…) in favor of a null check, we'd have to trigger anyway in the case of and exists success. This will avoid triggering an additional query. --- .../data/jpa/repository/support/SimpleJpaRepository.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index b4bf2de8f..50f430775 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -125,12 +125,14 @@ public class SimpleJpaRepository implements JpaRepos Assert.notNull(id, "The given id must not be null!"); - if (!exists(id)) { + T entity = findOne(id); + + if (entity == null) { throw new EmptyResultDataAccessException(String.format("No %s entity with id %s exists!", entityInformation.getJavaType(), id), 1); } - delete(findOne(id)); + delete(entity); } /*