ColdFusion 9 Air ORM Bug (Memory leak?)
I am spending a lot of time trying to figure out how this ORM stuff works on the Air side of things. The lack of documentation makes it very difficult to determine if a problem I am encountering is a bug, or an error in how I have something implemented.
In this case, I think it is a bug (which I have logged in the ColdFusion 9 Bug Database [EDIT: Bug Verified by Adobe 1/13/2010] [EDIT: Bug Fixed 1/25/2010 ColdFusion 9.0.1 ,Beta 1, Build 268370]). It has to do with recursive self joins (I'm sure there is a much cooler sounding name for it, but that's all I've got). Here's an example of what I mean.
Like most of my tables, the Users table in my database has a created_by_users_ID column that holds the user ID of the person who created that specific user record. It also has a modified_by_users_ID, which just as it's name suggests contains the user ID of the user who last modified the user record.
Here's my CFC entity (well, scaled down to be more meaningful)
<cfcomponent persistent="true" table="users" output="false" alias="Users">
<!---- properties ---->
<cfproperty name="ID" column="ID" type="numeric" ormtype="int" fieldtype="id" />
<cfproperty name="user_name" column="user_name" type="string" ormtype="string" />
<cfproperty name="password" column="password" type="string" ormtype="string" />
<!---- relationships ---->
<cfproperty name="createdByUser" fieldtype="many-to-one" cfc="users" fkcolumn="created_by_users_ID" />
<cfproperty name="modifiedByUser" fieldtype="many-to-one" cfc="users" fkcolumn="modified_by_users_ID" />
</cfcomponent>
And here's the Users.as entity:
package com.myproject.model.vo
{
[]
[(alias="Users")]
[]
public class Users
{
[]
public var ID:int;
public var user_name:String;
public var password:String;
// Relationships
[(targetEntity="com.myproject.model.vo::Users",fetchType="EAGER")]
[(name="created_by_users_ID",referencedColumnName="ID")]
public var createdByUser:Users;
[(targetEntity="com.myproject.model.vo::Users",fetchType="EAGER")]
[(name="modified_by_users_ID",referencedColumnName="ID")]
public var modifiedByUser:Users;
public function Users()
{
}
}
}
Super simple.
Now if I call my fetchCFC tester method (which basically does <cfdump var="#EntityLoad(arguments.entity)#">) I get my Users output as expected. I also see this in my joined columns:

Notice the [see cfc. for users details]. This is how CF is handling the recursions. Good. Now when I try to fetch from the Flex/Air side I get a infinite loop that slowly eats away all my memory until I end the adl.exe process. Note: Stopping the debugging session doesn't kill the adl.exe in this case, I have to kill it via task manager.
Maybe there's a way to prevent this, but I can't find any documentation. For now I've simply removed the relationships from the Users entity (as it is currently the only one that joins to itself) and I just manually update the integer values with the PK value of the appropriate user record.