Post-Insert Event Unexpected Behavior

Description

I am working with Hibernate 3.5.6 trying to make use of the Post-Insert event listener. I encountered a behavior which seems inconsistent with the notion of post processing an event. I go to commit an object to the DB which causes the session to be flushed and the post-insert event to be triggered. After the post-insert event is triggered, it does some processing and eventually throws an error which then travels all the way back to the original transaction. It is here that the error is caught. I am unable to rollback the transaction from this point and there is no entry in the DB. I have confirmed my code performs as expected if the post-insert event listener is removed.

Is it the expected behavior of a post-anything event in hibernate to affect the original transaction? My understanding is that a post event should be wholly independent of the original transaction.

Please see code segments and stack trace below.

Thanks for your help in advance.
-Chris

STACK TRACE
at ems.server.domain.IpeManager.getCrcMessage(IpeManager.java:113) ~[bin/:na]
at ems.shared.hibernateEvents.PostInsertListener.onPostInsert(PostInsertListener.java:34) [bin/:na]
at org.hibernate.action.EntityInsertAction.postInsert(EntityInsertAction.java:148) [hibernate3.jar:3.5.6-Final]
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:127) [hibernate3.jar:3.5.6-Final]
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:267) [hibernate3.jar:3.5.6-Final]
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:259) [hibernate3.jar:3.5.6-Final]
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:178) [hibernate3.jar:3.5.6-Final]
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) [hibernate3.jar:3.5.6-Final]
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) [hibernate3.jar:3.5.6-Final]
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206) [hibernate3.jar:3.5.6-Final]
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375) [hibernate3.jar:3.5.6-Final]
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137) [hibernate3.jar:3.5.6-Final]
at ems.server.database.dao.Dao.saveOrUpdate(Dao.java:30) [bin/:na]
at ems.server.database.dao.IpeComponentDao.insertComponent(IpeComponentDao.java:29) [bin/:na]
at ems.server.domain.NetworkManager.insertIpeConfig(NetworkManager.java:2876) [bin/:na]

DAO CLASS
Session session = HibernateUtil.currentSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.saveOrUpdate(obj);
tx.commit();
return obj;
} catch (ConstraintViolationException e) {
if (tx != null)
tx.rollback();
throw e;
} catch (HibernateException he) {
if (tx != null)
tx.rollback();
throw new HibernateException("Could not save object of class " + obj.getClass().getName(), he);
}

Hibernate.cfg.xml
<event type="post-insert">
<listener class="ems.shared.hibernateEvents.PostInsertListener"/>
</event>

PostInsertListener Class

package ems.shared.hibernateEvents;

import java.util.*;

import org.hibernate.event.PostInsertEvent;
import org.hibernate.event.PostInsertEventListener;

public class PostInsertListener implements PostInsertEventListener{

private static final long serialVersionUID = 2L;

public void onPostInsert(PostInsertEvent event) {
//DO SOME PROCESSING HERE
}
}

Environment

3.5.6, HyperSQL In Memory Database

Activity

Show:
Brett Meyer
December 19, 2013, 5:04 PM

These types of questions are best started in the user forums: https://forum.hibernate.org/viewforum.php?f=1. Please open JIRA tickets only when a concise, reproducible issue is identified. Thanks!

Assignee

Unassigned

Reporter

Christopher Wendling

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure