Skip to content

Commit c47ff56

Browse files
committed
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.
1 parent 6e5bbde commit c47ff56

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,9 @@ public <S extends T> S save(S entity) {
488488
if (entityInformation.isNew(entity)) {
489489
em.persist(entity);
490490
return entity;
491-
} else if (!em.contains(entity)) {
491+
} else {
492492
return em.merge(entity);
493493
}
494-
495-
return entity;
496494
}
497495

498496
/*

src/test/java/org/springframework/data/jpa/repository/support/SimpleJpaRepositoryUnitTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ public void mergeGetsCalledWhenDetached() {
145145
verify(em).merge(detachedUser);
146146
}
147147

148-
@Test // DATAJPA-931
149-
public void mergeGetsNotCalledWhenAttached() {
148+
@Test // DATAJPA-931, DATAJPA-1261
149+
public void mergeGetsCalledWhenAttached() {
150150

151151
User attachedUser = new User();
152152

153153
when(em.contains(attachedUser)).thenReturn(true);
154154

155155
repo.save(attachedUser);
156156

157-
verify(em, never()).merge(attachedUser);
157+
verify(em).merge(attachedUser);
158158
}
159159
}

0 commit comments

Comments
 (0)