On Tuesday, January 27, 2015 at 9:20:15 AM UTC-5, Nando Breiter wrote:
Well, here was the hack that works in Railo and ACF10. Putting this in its own thread allowed for a new transaction since it appears to be a new Hibernate session and for it to persist properly. Then, I check for an exception in the thread and "rethrow" it, which will rollback the previous transaction.
public void function postInsert() {
if (structKeyExists(variables, "updateMementos")) {
// HACK: for whatever reason, this entity will not persist in the current session
// so putting it in a thread and watching for exceptions is the workaround
thread name="tAuditLog#createUUID()#" action="run" entity=this data=variables.updateMementos.current {
transaction {
oAuditLog = entityNew('AuditLog');
oAuditLog.setRowID(entity.getIdentityValue());
oAuditLog.setRowData(data);
oAuditLog.setTableName(entity.getTableName());
oAuditLog.setChangeType('insert');
entitySave(oAuditLog);
}
}
thread action="join";
// throw an exception if the thread did not complete
// this rolls back the previous transaction
if (structKeyExists(cfthread[structKeylist(cfthread)], "error")) {
throw (attributeCollection=cfthread[structKeylist(cfthread)].error);
}
}
}