Dumping Results of EntityLoads in ColdFusion 9 ORM
Posted At : August 28, 2009 1:52 PM | Posted By : Bob Silverberg
Related Categories: ColdFusion, CF ORM Integration
I've started to do some more testing with ColdFusion 9's Hibernate (ORM) integration, and I noticed something interesting about a cfdump result. I've got an entity called UserGroup, and I wanted to see a dump of the results of calling EntityLoad in different ways, so I ran the following script:
2 stuff = {};
3 stuff.allGroups = EntityLoad("UserGroup");
4 stuff.group1AsArray = EntityLoad("UserGroup",1);
5 stuff.group1AsObject = EntityLoad("UserGroup",1,true);
6</cfscript>
7<cfdump var="#stuff#">
And this is what I see:
Notice that in the first key in the struct, allGroups, which is the result of the call to EntityLoad("UserGroup"), I can see two objects which represent two records in the underlying table. Notice that in the second key in the struct, group1AsArray, I don't see any info on the object itself, but rather a pointer back to the dump of the object in the allGroups key. The same holds true for the final key in the struct, group1AsObject.
If I remove the call to EntityLoad("UserGroup"), like so:
2 stuff = {};
3 stuff.group1AsArray = EntityLoad("UserGroup",1);
4 stuff.group1AsObject = EntityLoad("UserGroup",1,true);
5</cfscript>
6<cfdump var="#stuff#">
then my dump looks like this:
Notice that again the actual dump of the object only appears once, in the first key, with a pointer to the first key appearing in the second key.
Perhaps this is linked in some way to Hibernate's session cache, or maybe it's just a way for Adobe to optimize cfdump for ORM entities. Either way I'm not sure that the information (about how cfdump output appears) is particularly useful, but I do find it interesting.
Let's say you have departments and employees related to each other in a many employees to one department relationship. When you dump an employee, it would contain a department object. That department object would contain an array of employees which would include the originally dumped employee, which would contain a department, which contains an array of employees....
Early tests of ORM entities and dump caused cfdump to go into infinite loops. Now it only dumps an object once and puts a reference to other spots where it would show.
One bit of usefullnes from this is the fact that you can visually see what are just pointers and what's not.