ORM Event handlers and audit records

19 views
Skip to first unread message

Jonathan Price

unread,
Apr 18, 2015, 1:28:00 AM4/18/15
to cf-or...@googlegroups.com
We keep audit records for some DB tables in our system, and I'm running into an ID problem with postInsert. I'm new with these handlers, and really would appreciate any critique of the procedure. Goes something like

component persistent="true" table="Object1" {
property name="id" fieldtype="id" column = "Object1ID" generator="identity";
property name="Field1" type="string";

public void function postInsert() {
var history = EntityNew('Object1History');
history.setField1(this.getField1());
history.setObject1(this);
}
}

component persistent="true" table="Object1History" {
property name="id" fieldtype="id" column = "Object1HistoryID" generator="identity";
property name="Field1" type="string";
property name="Object1" fieldtype="many-to-one cfc="Object1" fkcolumn="Object1ID";
}

And the update code is something like:

local.obj = EntityNew("Object1");
local.obj.setField1('something here');

EntitySave(local.obj);

And I'm getting an error about Object1ID not being allowed a null value, presumable because of the 'history.setObject1(this)' bit.

My questions are 1) Can I even do this? and 2) Is anyone else doing something similar? it's seems like these even handlers are ready made for this stuff.

Andrew Scott

unread,
Apr 18, 2015, 7:26:23 AM4/18/15
to cf-or...@googlegroups.com
Due to the way ColdFusion uses the ORM session, you will get this error. The workaround is to use HQL to do your auditing here instead. There was an E/R to fix this, because it is something that should be allowed to work here, but I have not kept up with that ticket and to be honest, Adobe are good at implementing things without any thought to its consequences.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/



--
You received this message because you are subscribed to the Google Groups "cf-orm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cf-orm-dev+...@googlegroups.com.
To post to this group, send email to cf-or...@googlegroups.com.
Visit this group at http://groups.google.com/group/cf-orm-dev.
For more options, visit https://groups.google.com/d/optout.

Nando Breiter

unread,
Apr 18, 2015, 7:28:46 AM4/18/15
to cf-or...@googlegroups.com
Without going into detail, I'm doing something similar, but wound up
using sql insert statements into the audit tables. I'll reply more in
depth later.

Andrew Scott

unread,
Apr 18, 2015, 7:39:47 AM4/18/15
to cf-or...@googlegroups.com
SQl or HQL will work fine. I just chose to use ExecuteQuery for HQL over SQL.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/


Reply all
Reply to author
Forward
0 new messages