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:
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ public class SimpleJpaRepositoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAJPA-1535
|
||||
public void doNothingWhenNonExistantInstanceGetsDeleted() {
|
||||
public void doNothingWhenNonExistentInstanceGetsDeleted() {
|
||||
|
||||
User newUser = new User();
|
||||
newUser.setId(23);
|
||||
|
||||
Reference in New Issue
Block a user