Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement triggers in hibernate

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 ?

like image 915
Juzer Arsiwala Avatar asked Dec 20 '10 02:12

Juzer Arsiwala


People also ask

How do you call a trigger 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 ...

What is remove method in Hibernate?

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.


1 Answers

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.

like image 150
Diego Mijelshon Avatar answered Sep 18 '22 15:09

Diego Mijelshon