DATAJPA-1535 - Polishing.

Use isNew(…) check in delete(T) instead of just relying on Id nullability. Formatting.

Original pull request: #378.
This commit is contained in:
Mark Paluch
2019-05-21 10:37:27 +02:00
parent c1d99ae77e
commit 44b839ff88
4 changed files with 10 additions and 10 deletions

View File

@@ -169,13 +169,11 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
Assert.notNull(entity, "The entity must not be null!");
Object id = entityInformation.getId(entity);
if (id == null) {
if (entityInformation.isNew(entity)) {
return;
}
T existing = em.find(entityInformation.getJavaType(), id);
T existing = em.find(entityInformation.getJavaType(), entityInformation.getId(entity));
// if the entity to be deleted doesn't exist, delete is a NOOP
if (existing == null) {
return;

View File

@@ -174,12 +174,13 @@ public class EclipseLinkNamespaceUserRepositoryTests extends NamespaceUserReposi
super.findByEmptyCollectionOfStrings();
}
/**
* Ignores the test for EclipseLink.
*/
@Override
@Test
@Ignore
public void savingUserThrowsAnException() {
super.savingUserThrowsAnException();
}
public void savingUserThrowsAnException() {}
private void assumeNotEclipseLink2_7_2plus() {

View File

@@ -2211,9 +2211,10 @@ public class UserRepositoryTests {
assertThat(repository.findByEmailNativeAddressJdbcStyleParameter("gierke@synyx.de")).isEqualTo(firstUser);
}
@Test() // DATAJPA-1535
@Test // DATAJPA-1535
public void savingUserThrowsAnException() {
// if this test fails this means deleteNewInstanceSucceedsByDoingNothing() might actually save the user without the test failing, which would be a bad thing.
// if this test fails this means deleteNewInstanceSucceedsByDoingNothing() might actually save the user without the
// test failing, which would be a bad thing.
assertThatThrownBy(() -> repository.save(new User())).isInstanceOf(DataIntegrityViolationException.class);
}

View File

@@ -171,7 +171,7 @@ public class SimpleJpaRepositoryUnitTests {
}
@Test // DATAJPA-1535
public void doNothingWhenNonExistantInstanceGetsDeleted() {
public void doNothingWhenNonExistentInstanceGetsDeleted() {
User newUser = new User();
newUser.setId(23);