I want to implement something similar to triggers in hibernate.
What I need is when a column in a table attains a specific value, a row should be inserted in another table or some other table should be updated.
How do I implement this in hibernate ?
There is no direct way to create a database trigger through Hibernate, this is very database specific and best done with the database tools (or a PL/SQL editor). Well, you can create a trigger, and then it will be triggered when Hibernate inserts ...
In Hibernate, an entity can be removed from a database by calling the Session#delete() or Session#remove() . Using these methods, we can remove a transient or persistent object from datastore. The following examples demonstrate the use of Session#delete() and Session#remove() methods.
That's described in Chapter 14. Interceptors and events.
You can, for example, intercept a post-update event.
However, using the event system for business operations might not be the best idea (they are best used for infrastructure concerns). You should use a higher level layer for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With