hi,
plain vanilla session-factory-scoped interceptor: is there anyway to participate in the transaction of the caller?
e.g. a Report object is being saved. in the onSave method body i would like to insert a record into a dependant ReportInfo table.
because of the FK constraint in the dependant ReportInfo table, i can not insert the dependent record unitil the parent record has commited. the following code snippet will cause the FK contraint violation:
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException {
if(entity instanceof Report == true){
log.info("onSave(): " + entity.getClass());
Report r = (Report)entity;
ReportInfo i = synchIntComp(r);
Session newSession =
HibernateUtil.sessionFactory.openSession(
HibernateUtil.currentSession().connection());
Transaction tx = newSession.beginTransaction();
newSession.save(i);
tx.commit();
newSession.flush();
newSession.close();
}
return false;
}
thanks!
tom
|