mirror of
https://github.com/google/nomulus.git
synced 2025-07-23 03:06:01 +02:00
Detach entities loaded by loadSingleton() (#1184)
* Detach entities loaded by loadSingleton() * Reformatted
This commit is contained in:
parent
810adf0158
commit
92f5f8989b
2 changed files with 14 additions and 1 deletions
|
@ -504,7 +504,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||||
elements.size() <= 1,
|
elements.size() <= 1,
|
||||||
"Expected at most one entity of type %s, found at least two",
|
"Expected at most one entity of type %s, found at least two",
|
||||||
clazz.getSimpleName());
|
clazz.getSimpleName());
|
||||||
return elements.stream().findFirst();
|
return elements.stream().findFirst().map(this::detach);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int internalDelete(VKey<?> key) {
|
private int internalDelete(VKey<?> key) {
|
||||||
|
|
|
@ -508,6 +508,19 @@ class JpaTransactionManagerImplTest {
|
||||||
assertThat(persisted).containsExactlyElementsIn(moreEntities);
|
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
|
@Test
|
||||||
void delete_succeeds() {
|
void delete_succeeds() {
|
||||||
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue