• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create a trigger with Hibernate ?

 
Eusebio Floriano
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is possible to create a trigger with hibernate ?
Example,
The system always save an log when a data was inserted in DB.

Regards,
 
Christian Bauer
author
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways to do this kind of logging inside Hibernate (Hibernate Interceptor, Hibernate3 Events), you can also make Hibernate aware of an existing trigger in the database by refreshing after a flush operation. 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).
 
Gavin King
author
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you can create a trigger, and then it will be triggered when Hibernate inserts ... thats kinda the point ;-)


Or, you can use the Hibernate Interceptor API, if you want a "Java-level tigger".
 
Eusebio Floriano
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gavin King:
Well, you can create a trigger, and then it will be triggered when Hibernate inserts ... thats kinda the point ;-)


Or, you can use the Hibernate Interceptor API, if you want a "Java-level tigger".


Yeap .. Exactly what i would like .. an appliacation trigger.
I�ll take a look at Hibernate Interceptor API.

Thx,
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an appliacation trigger. I�ll take a look at Hibernate Interceptor API.


...and if this is still not enough you can always go to AOP :-).
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi authors,

Do you have example code to use Trigger with Hibernate ??
 
Gavin King
author
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interceptor, you mean?

http://www.hibernate.org/hib_docs/reference/en/html/manipulatingdata.html#manipulatingdata-interceptors
 
Eusebio Floriano
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ali Pope:


...and if this is still not enough you can always go to AOP :-).


The problem is that my company still doesn�t look at AOP with good eyes.
It will spend some time to my company accept it.
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AOP adoption is hard to some high levels :-), but using good tactics (running examples, pointing to good documentation/forums) will finally make it a winner. I've already done this for 2 employers ;-).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic