Home > other >  Modifying a child Entity on delete of parent Entity
Modifying a child Entity on delete of parent Entity

Time:01-26

I've got a Person class that can be an invitee to multiple Events. An Event keeps track of people and also a list of phonenumbers, for people that don't have a record in Person. When a Person gets deleted, we want to move their phone number to the list of phonenumbers for events that that person was invited to.

I've considered using @PreRemove in Person, but Spring doesn't like injecting an event repository in the User entity. Nor is there a way to save the particular Person within @PreRmove and do a cascade persist.

I've also considered doing an event listener, but I get a circular dependency error when I inject either an event or person repository inside there to perform a save on the events.

Is there a way to do to this in Spring?

CodePudding user response:

Thanks to Andrey for the suggestion. Following this article on @DomainEvents, I was able to get this working.

  • Related