DATAJPA-1261 - Revert optimizations made for existing entities in implementation of CrudRepository.save(…).

This reverts the functional change made by DATAJPA-931. This means merge will be called again, even if the entity for which save was called is already attached to the session. Tests stay in place to verify the new old behavior.

Related ticket: DATAJPA-931.
Original pull request: #249.
This commit is contained in:
Jens Schauder
2018-02-05 12:14:29 +01:00
committed by Oliver Gierke
parent 247f67d33c
commit 68fcf6ef8f
2 changed files with 4 additions and 6 deletions

View File

@@ -489,11 +489,9 @@ public class SimpleJpaRepository<T, ID> implements JpaRepository<T, ID>, JpaSpec
if (entityInformation.isNew(entity)) {
em.persist(entity);
return entity;
} else if (!em.contains(entity)) {
} else {
return em.merge(entity);
}
return entity;
}
/*

View File

@@ -145,8 +145,8 @@ public class SimpleJpaRepositoryUnitTests {
verify(em).merge(detachedUser);
}
@Test // DATAJPA-931
public void mergeGetsNotCalledWhenAttached() {
@Test // DATAJPA-931, DATAJPA-1261
public void mergeGetsCalledWhenAttached() {
User attachedUser = new User();
@@ -154,6 +154,6 @@ public class SimpleJpaRepositoryUnitTests {
repo.save(attachedUser);
verify(em, never()).merge(attachedUser);
verify(em).merge(attachedUser);
}
}