For experimental "transparent persistence" - Delete removes from PC early

When delete bean executed with transparent persistence, this marks the bean as removed from the persistence context early.

This avoids a "dirty" deleted bean from being seen as a "dirty" bean in the persistence context at flush() time.
This commit is contained in:
Robin Bygrave
2021-04-01 16:04:18 +13:00
parent a617d58902
commit ba397bbb0c
3 changed files with 32 additions and 0 deletions
@@ -17,6 +17,29 @@ import static org.assertj.core.api.Assertions.assertThat;
public class TestTransparentPersist extends BaseTestCase {
@Test
public void delete_expect_beanRemovedFromPersistenceContext() {
EBasicVer b0 = new EBasicVer("simpleDelete");
DB.save(b0);
try (Transaction transaction = DB.beginTransaction()) {
transaction.setTransparentPersistence(true); // EXPERIMENTAL feature
EBasicVer found = DB.find(EBasicVer.class, b0.getId());
// make it dirty
found.setName("make it dirty");
// delete it, should remove it from the "live" part of persistence context
// with the expectation that no update is executed (no dirty in PC update)
DB.delete(found);
transaction.commit();
}
EBasicVer after = DB.find(EBasicVer.class, b0.getId());
assertThat(after).isNull();
}
@Test
public void simpleInsertUpdateDelete_experimental() {