test(person): describe DB-cascade mechanism in delete service-path test (#684)
The deletePerson service-path guard (AC-4) is unchanged behaviourally, but its comments described the removed reassignSenderToNull/deleteReceiverReferences chain. Update them to the V71 ON DELETE cascade mechanism. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -180,9 +180,9 @@ class PersonServiceIntegrationTest {
|
|||||||
@Test
|
@Test
|
||||||
void deletePerson_detachesSentAndReceivedReferences_beforeDelete_noOrphan() {
|
void deletePerson_detachesSentAndReceivedReferences_beforeDelete_noOrphan() {
|
||||||
// A person referenced as BOTH a document sender and a document receiver must delete
|
// A person referenced as BOTH a document sender and a document receiver must delete
|
||||||
// cleanly: deletePerson nulls the sender_id FK and removes the receiver join row first
|
// cleanly via the service path: deletePerson just calls deleteById, and V71's ON DELETE
|
||||||
// (reassignSenderToNull → deleteReceiverReferences → deleteById), so no FK orphan and
|
// constraints null the sender_id FK and drop the receiver join row, so there is no FK
|
||||||
// the documents themselves survive.
|
// orphan and the documents themselves survive.
|
||||||
Person target = personRepository.save(Person.builder()
|
Person target = personRepository.save(Person.builder()
|
||||||
.firstName("Weg").lastName("Person").provisional(true).build());
|
.firstName("Weg").lastName("Person").provisional(true).build());
|
||||||
Person bystander = personRepository.save(Person.builder()
|
Person bystander = personRepository.save(Person.builder()
|
||||||
@@ -196,16 +196,16 @@ class PersonServiceIntegrationTest {
|
|||||||
.status(DocumentStatus.UPLOADED).sender(bystander)
|
.status(DocumentStatus.UPLOADED).sender(bystander)
|
||||||
.receivers(new java.util.HashSet<>(Set.of(target))).build());
|
.receivers(new java.util.HashSet<>(Set.of(target))).build());
|
||||||
|
|
||||||
// Persist the fixture and detach everything so the native @Modifying deletes operate on
|
// Persist the fixture and detach everything so the delete operates on the database
|
||||||
// the database directly without the persistence context holding stale references that
|
// directly without the persistence context holding stale references.
|
||||||
// would re-flush a now-deleted person as a transient association.
|
|
||||||
entityManager.flush();
|
entityManager.flush();
|
||||||
entityManager.clear();
|
entityManager.clear();
|
||||||
|
|
||||||
personService.deletePerson(target.getId());
|
personService.deletePerson(target.getId());
|
||||||
|
|
||||||
// Native @Modifying queries bypass the persistence context — clear it so the asserting
|
// The ON DELETE cascade fires beneath Hibernate — flush the delete and clear the L1
|
||||||
// reads observe the post-delete database state, not stale managed entities.
|
// cache so the asserting reads observe the post-delete database state, not stale
|
||||||
|
// managed entities (the EAGER @ElementCollection on receivers makes this load-bearing).
|
||||||
entityManager.flush();
|
entityManager.flush();
|
||||||
entityManager.clear();
|
entityManager.clear();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user