mirror of
https://github.com/google/nomulus
synced 2026-04-24 02:00:50 +00:00
Detach entities loaded by loadSingleton() (#1184)
* Detach entities loaded by loadSingleton() * Reformatted
This commit is contained in:
@@ -504,7 +504,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||
elements.size() <= 1,
|
||||
"Expected at most one entity of type %s, found at least two",
|
||||
clazz.getSimpleName());
|
||||
return elements.stream().findFirst();
|
||||
return elements.stream().findFirst().map(this::detach);
|
||||
}
|
||||
|
||||
private int internalDelete(VKey<?> key) {
|
||||
|
||||
@@ -508,6 +508,19 @@ class JpaTransactionManagerImplTest {
|
||||
assertThat(persisted).containsExactlyElementsIn(moreEntities);
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadSingleton_detaches() {
|
||||
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||
jpaTm()
|
||||
.transact(
|
||||
() ->
|
||||
assertThat(
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.contains(jpaTm().loadSingleton(TestEntity.class).get())))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_succeeds() {
|
||||
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||
|
||||
Reference in New Issue
Block a user