Created
February 5, 2012 12:44
-
-
Save lgueye/1745351 to your computer and use it in GitHub Desktop.
Configure hibernate listeners prior to hibernate 4.0.0.Final
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author [email protected] | |
*/ | |
@Component | |
public class HibernateListenersConfigurer { | |
@Autowired | |
private EntityManagerFactory entityManagerFactory; | |
@Autowired | |
private PreInsertEventListener preInsertEventListener; | |
@Autowired | |
private PreUpdateEventListener preUpdateEventListener; | |
@Autowired | |
private PreDeleteEventListener preDeleteEventListener; | |
@PostConstruct | |
public void registerListeners() { | |
HibernateEntityManagerFactory hibernateEntityManagerFactory = (HibernateEntityManagerFactory) this.entityManagerFactory; | |
SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) hibernateEntityManagerFactory.getSessionFactory(); | |
sessionFactoryImpl.getEventListeners().setPreInsertEventListeners( | |
new org.hibernate.event.PreInsertEventListener[] { this.preInsertEventListener }); | |
sessionFactoryImpl.getEventListeners().setPreUpdateEventListeners( | |
new org.hibernate.event.PreUpdateEventListener[] { this.preUpdateEventListener }); | |
sessionFactoryImpl.getEventListeners().setPreDeleteEventListeners( | |
new org.hibernate.event.PreDeleteEventListener[] { this.preDeleteEventListener }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment