Giriş
Şu satırı dahil ederiz
import org.hibernate.event.spi.PostDeleteEventListener;
Örnek
Şöyle yaparız
public class HibernateCDCEventListener implements PostDeleteEventListener,PostUpdateEventListener, PostInsertEventListener { public HibernateCDCEventListener(EntityManagerFactory entityManagerFactory) { SessionFactoryImplementor sessionFactory = entityManagerFactory .unwrap(SessionFactoryImplementor.class); EventListenerRegistry eventListenerRegistry = sessionFactory.getServiceRegistry() .getService(EventListenerRegistry.class); eventListenerRegistry.appendListeners(POST_DELETE, this); eventListenerRegistry.appendListeners(POST_UPDATE, this); eventListenerRegistry.appendListeners(POST_INSERT, this); } @Override public void onPostDelete(final PostDeleteEvent event) { // Handle delete events } @Override public void onPostInsert(final PostInsertEvent event) { processEntity(event.getEntity(), event.getEntity(), event.getEntity()); } @Override public void onPostUpdate(final PostUpdateEvent event) { processEntity(event.getEntity(), event.getEntity(), event.getEntity()); } @Override public boolean requiresPostCommitHanding(final EntityPersister persister) { return false; } }
Hiç yorum yok:
Yorum Gönder