Gavin wrote:
>You can save and delete from Lifecycle callbacks.
Yes, but the Lifecycle callbacks are called before the operation is performed. This is a particular problem for onSave(), because at that point the master object doesn't have an identifier. This limits my ability to create associations.
>(but why would you not just use cascades?
Maybe cascades would help me with some relationships. (Can you point me to an explanation? I grepped Cascade out of the JavaDoc but could not find any place where it was defined. I can see the Cascade JavaDoc, but not an explanation of what to do with it.) But some activities that I would like to do in postFlush() can't be accomplished with cascades.
For instance: I have entities, called Domains, which have a parent-child relationship that is defined by a mapping table. When that mapping table is updated, triggers cause objects to be created and deleted in another mapping table. (Yes, this is horrible, but the database was designed long before we were using Hibernate.) So when Domain relationships change, I would like to do some code in postFlush() to load new entities to represent the changes that were performed by the database triggers.
By the way, I really appreciate you and David's prompt responses. I am trying to do some pretty involved stuff using Hibernate. The purpose of this post is to see if anyone else had this experience and had a solution that I could learn from.
|