the singularity of being and nothingness
ColdFusion ORM – Collection…was not processed by flush()
This is more for my own memory, but perhaps it will be useful to others 🙂
Let’s say I have the following entities:
User.cfc
component persistent="true" entityname="User" table="User" { property name="UserID" fieldtype="id"; property name="Name"; property name="Age"; property name="Group" fieldtype="many-to-one" cfc="Group" fkcolumn="GroupID"; }
 Group.cfc
component persistent="true" entityname="Group" table="Group" { property name="GroupID" fieldtype="id"; property name="Name"; property name="Activities" fieldtype="one-to-many" fkcolumn="GroupID" linktable="Activity" inversejoincolumn="ActivityID"; }
Ok, so let’s also imagine that I’m trying to leverage the postDelete() event to make an audit record of any User deletions that I make:
// function postDelete( entity ) { // get properties from entity that I want to log ... ... }
When I try to do this, I get something like:
collection >> [Group.Activities] was not processed by flush()
I banged my head on this wall for a while, until I finally figured out the issue.
The issue is the “laziness” of the “Group” property on the User entity. Since I have no value specified, it is equivalent to having specified “lazy=true”. Since (I assume) the Group property is not being fully “loaded” during the delete operation, there’s no chance that it’s own “Activities” property is loaded either…hence the error.
Anyway, to fix this, I merely added “lazy=false” to my “Group” property. Once in place, I was able to delete AND do my auditing without any errors.
Print article | This entry was posted by existdissolve on November 14, 2012 at 9:56 pm, and is filed under ColdFusion. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 10 years ago
Any idea if there is a solution for when you need lazy=true on certain properties?
about 9 years ago
I ran into the same issue today where in my postInsert, postUpdate, and postDelete, I was creating a new thread for auditing and passing the entity to that thread as an attribute: https://groups.google.com/forum/#!topic/cf-orm-dev/ikH3YbWNL6o
This worked fine in Railo, but ACF could not handle this and was giving me the same flush issue you saw. I tried duplicating the entity, merging it into the new session within the thread, refreshing it, etc. No go. Finally I decided to set the attributes from the entity outside of the thread and pass them in so the dependency on the entity was no longer there and it worked like a charm… ACF’s implementation of Hibernate has given me such a headache 🙂
public void function postInsert() {
if (structKeyExists(variables, “updateMementos”)) {
var data = variables.updateMementos.current;
var entityData = {
id = getIdentityValue(),
table = getTableName()
};
// 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=”tAuditLogInsert#createUUID()#” action=”run” entity=local.entityData rowData=local.data {
transaction {
oAuditLog = entityNew(‘AuditLog’);
oAuditLog.setRowID(attributes.entity.id);
oAuditLog.setRowData(attributes.rowData);
oAuditLog.setTableName(attributes.entity.table);
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);
}
}
}