4

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..

1 Answer 1

6

You can create a generic DAO, and make use of some kind of interceptor.

Resources:

2
  • Thanks for response, can u explain in detail or is there any related link.
    – hnm
    Mar 1, 2011 at 5:07
  • @hnm: Updated my post to include some resources. Mar 1, 2011 at 5:17

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.