title: Invoking Hibernate PostInsertEventListener after flush
body: <p>I have a class implementing Hibernate <code>PostInsertEventListener</code> which is tied to the Hibernate <code>SessionFactory</code> via Spring. The interceptor is specified for <code>post-insert</code> event type . This interceptor gets invoked whenever I perform a <code>session.save(entity)</code>. However, the execution happens before the transaction is flushed. This is problematic if the database throws an exception.</p>
  
  <p><strong>Question:</strong>
  Is there a way I can specify to invoke an interceptor <strong>after</strong> the <code>session.flush()</code> has been called?</p>
  
  <p>I tried doing <code>insertEvent.getSession().flush()</code> within the event listener but that produces a primary key violation exception since the id was not yet set.</p>
  
  <p>I have not yet explored the <code>registerSynchronization</code> way because it seems like I am missing some basic configuration. The transaction manager being used is <code>org.springframework.orm.hibernate3.HibernateTransactionManager</code> and the transactional boundaries are specified by the <code>@Transactional</code> annotation. Hibernate version is 3.6</p>