I have a class that implements a Hibernate PostInsertEventListener that is bound to a Hibernate SessionFactory through Spring. An interceptor is specified for the post-insert event type. This interceptor is called whenever I execute session.save(entity) . However, execution occurs before the transaction is cleared. This is problematic if the database throws an exception.
Question: Is there a way that I can specify to call the interceptor after session.flush() was called?
I tried to execute insertEvent.getSession().flush() inside the event listener, but this throws a primary key violation because the identifier is not set yet.
I have not yet learned the registerSynchronization method, because it seems to me that I am missing a basic configuration. The transaction manager used is org.springframework.orm.hibernate3.HibernateTransactionManager , and transaction boundaries are determined by the @Transactional annotation. Version for sleep mode 3.6.
Rohit source share