I recently came across a situation where I have to do some actions when object is updated through Hibernate session, but hibernate session does not have any methods where I can add update listener. To summarize my intent I am posting a sample program.
public class SessionListenerTest{
public static void main(String[] args){
...
Session session = sessionFactory.openSession();
session.addSessionListener(new SessionListener(){
onUpdate(Object dbObject){
...
}
onDelete(Object dbObject){
...
}
onInsert(Object dbObject){
...
}
});
}
}
Whenever ant object is updated through hibernate session, onUpdate should be called and so on. But Hibernate session does not have any methods similar to addSessionListener. Any help is appreciated..
You can create a generic DAO, and make use of some kind of interceptor.
Resources: