One possible way, I think, is using one of entity lifecycle callbacks.
class Person {
@PreRemove
protected void makeHouseOnSale() {
if (owning!= null) {
owning.owner = null;
}
}
@OneToOne
private House owning;
}
class House {
@OneToOne(
//optional = true; // default
)
private Person owner;
}
When you remove(kill) a Person
instance in JTA
session, @PreRemove
annotated methods are invoked and those two entities commits when the session ends.