Hi, I wanted to ask about possible scenario.
Entity with @PostPersist annotated method is being persisted as a result persist cascade, this is happening during flush at the end of transaction.
The @PostPersist method modifies or persists other entities.
My question is will hibernate handle all those changes to other entities in the @PostPersist method happening during flush at the end of transaction?
Sorry if this is a stupid question. I just want to be sure that it works as I expect.
Hi @mira-silhavy, since
@PostPersist and other life cycle callback methods are called during session flush any changes to entities or new persisted instances would not be included in the same flush, I suspect would they wouldn’t even trigger an automatic subsequent flush I think.
In general, I would be careful modifying the state of persistent entities in life cycle callback methods. The main risks I see, especially since you’re using cascade, is infinite recursion or unnecessary processing of the same entities.
Maybe you could share an example of what you’re trying to achieve so we could analyze the specific use-case. I think you should manage persistent entities outside of life cycle callbacks within your application or through cascading associations.