DATAJPA-177 - Throw exception if entity to delete does not exist.

We now do an exists check inside SimpleJpaRepository.delete(ID id) before actually triggering the deletion to avoid an exception when trying to delete a null value. We throw an EmptyResultDataAccessException to indicate the nonexistent entity now.
This commit is contained in:
Oliver Gierke
2012-04-15 20:24:41 +02:00
parent 24e4ac8e7b
commit 11d624f266
2 changed files with 17 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.sample.User;
@@ -81,4 +82,13 @@ public class SimpleJpaRepositoryUnitTests {
verify(query, times(0)).getResultList();
}
/**
* @see DATAJPA-177
*/
@Test(expected = EmptyResultDataAccessException.class)
public void throwsExceptionIfEntityToDeleteDoesNotExist() {
repo.delete(4711L);
}
}