Adding a listener to sleep mode

Recently, I came across a situation where I need to perform some actions when an object is updated through a Hibernate session , but there are no methods in the hibernate session where I can add an update listener. To summarize my intentions, I am sending 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){ ... } }); } } 

When the ant object is updated through a sleep session, onUpdate should be called , and so on. But a Hibernate session does not have methods similar to addSessionListener . Any help is appreciated.

+4
source share
1 answer

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

Resources

+6
source

Source: https://habr.com/ru/post/1341754/


All Articles