Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to create a trigger with Hibernate ?

 
Ranch Hand
Posts: 241
  • 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,
 
author
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).
 
author
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: 241
  • 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,
 
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 :-).
 
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
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: 241
  • 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 ;-).
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic