List of usage examples for org.hibernate.event.spi EventSource getFactory
HibernateEntityManagerFactory getFactory();
From source file:org.egov.infra.config.persistence.event.listener.HibernateEventListener.java
License:Open Source License
/** * When reading an object from within the PreInsert or PreUpdate event handlers, a different session has to be used from the * one in which the event was fired. This is to make sure that the objects loaded here are flushed. Otherwise it results in * collection was not processed by flush() Assertion failures * * @param session//from ww w .j a v a 2 s. c om * @return */ private User getUserObjectFromWithinEventListener(final EventSource session) { // Since we are already in the flush logic of our current session, // get the user object from a different session final SessionFactory factory = session.getFactory(); final Session session2 = factory.openSession(); final User usr = session2.load(User.class, ApplicationThreadLocals.getUserId()); session2.flush(); session2.close(); return usr; }