views:

41

answers:

1

I have a DB running on Oracle. I use Hibernate for data access. I want to be notified whenever an object is saved in the DB, so that I can do some custom work. I want an "event listener" if you could call it that. Is there a way to detect such task ?

+1  A: 

On Hibernate level, this is done using interceptors

On Oracle level, it's called trigger:

create or replace trigger <triggername>
before/after insert or update or delete
on <tablename> 
for each row/for each statement
...
mhaller
is it possible instead to use interceptors in Hibernate to intercept a persistent object before it is saved, updated or deleted ?
Attilah
sorry, i made a mistake . is it possible instead to use interceptors in Hibernate to intercept a persistent object <b>AFTER</b> it is saved, updated or deleted ?
Attilah
Have you looked into the Interceptor example? See the afterTransactionCompletion() method, which is called AFTER the object is saved/updated/deleted.
mhaller
hi mhaller, thanks for telling me about Hibernate interceptors but I can't make it work even though I followed the reference step by step : http://stackoverflow.com/questions/1701793/hibernate-interceptors-aftertransactioncompletion
Attilah