saveUpdateCache doesn't respect my Relationships

It seems that the further I get into CF9's Air/Orm stuff, the more roadblocks I find.  I guess this is to be expected with a first generation feature, but that doesn't make it any less frustrating - especially when you can't seem to get any community support and there is very little documentation.  I did just get a verified bug email from adobe for my bug on self joins, thanks Adobe!

Ok, got that out of the way.  Now to the problem.  When you define an entity with relationships in the CF9/Air orm and perform a fetch to retrieve the server's data for that entity the fetch call returns the parent entity data as well as all of the related entity data.  However, when you perform the saveUpdateCache with that result you'll find that it doesn't quite work correctly.

To explain this better, let me give a real example from my project (scaled down a bit for clarity): 

I have a table/entity called Companies.  Companies has a OneToOne relationship to Addresses and a ManyToMany relationship to Contacts.  It also has ManyToOne relationships to Users, CompanyTypes, and other various entities.  Many of these "child" entities also have relationships (i.e. Addresses has ManyToOne with States, etc...)  When I fetch the Companies entity from the CF server then call the saveUpdateCache() method it creates my SQLite tables for all related entities, but does not update all the data.  Here's what it does:

Parent entity (Companies) =  Creates SQLite table and inserts all data
OneToOne entities = Creates SQLite table and inserts all data
ManyToOne = Creates SQLite table and does not insert any data
ManyToMany = Creates SQLite table and inserts all data on the "linktable" but no data is inserted on the joined table

I have "EAGER" fetching on all relationships.  When I put breakpoints in to debug I can see that the results from the fetch contain all the data, including all of the joined data. 

Here's a sample of my relationships:

ManyToOne
//Company Type Relationship
[ManyToOne(targetEntity="com.
myproject.model.vo::CompanyTypes"
,fetchType="EAGER")]
[JoinColumn(name="company_types_ID",referencedColumnName="ID")]   
public var companyType:CompanyTypes;


ManyToMany
//Contacts Relationship
[ManyToMany(targetEntity="com.myproject.model.vo::Contacts", fetchType="EAGER")]
[JoinTable(name="companies_to_contacts")]
[JoinColumn(name="companies_ID",referencedColumnName="ID")]
[InverseJoinColumn(name="contacts_ID",referencedColumnName="ID")]
public var companyContacts:Array;

Currently what I have to do to get all the data is to call fetch for each child entity individually.  This is working for fetching and updating the local DB, but I have yet to test it on committing changes back to the server.

I have also logged this in the CF9 Bug Database.

Update: This bug was verified by the Adobe team today (March 8th 2010).  Let's hope for a quick fix!

Update 2: Fixed In: ColdFusion 9.0.1 ,Beta 1, Build 272693 (March 9th 2010).  That was pretty quick, now when can we download.....

Comments

Shoop

Shoop wrote on 01/14/10 2:17 PM

Thanks for sharing! I have the same problem with the manyTomany relations.
What do you think is the best way to fetch each entity individually ?
Abram

Abram wrote on 01/14/10 4:31 PM

@Shoop,
I don't think I can give the "best way", but basically how I do it is: I have my fetch method (on the CF side) setup to take a string argument: entity. I then return EntityLoad(arguments.entity).

On the AS3 side I have a "synchronize" method that also takes an entity string, which performs the fetch call for that entity and ultimately the saveUpdateCache.
Shoop

Shoop wrote on 01/26/10 2:46 PM

Hi, im loading all of the entities one by one. With one table i get the following error:

Error: Error #1023: Stack overflow occurred.at coldfusion.air::SessionToken()[D:\p4\depot\ColdFusion\cf_main\tools\AIRIntegration\OfflineSupport\src\coldfusion\air\SessionToken.as:73]

In the debugger i get this:

"undefined at coldfusion.air::SessionToken()[D:\p4\depot\ColdFusion\cf_main\tools\AIRIntegration\OfflineSupport\src\coldfusion\air\SessionToken.as:73]"

Have you seen this error before?
Abram

Abram wrote on 01/26/10 5:11 PM

Sounds like a recursion issue. Are you calling a method that calls itself that could be spinning out of control?
Shoop

Shoop wrote on 02/02/10 2:38 PM

No, i still don't know why it happens. I think it's related to the structure of the table.

At the moment i just create the SQLlite database with Coldfusion and download it to my adobe air app. Because the lack of proper ORM AIR documentation I'm using normal SQL queries within my application.
Abram

Abram wrote on 02/02/10 5:21 PM

One thing to watch for is self joins. This causes endless recursion and is a verified (and fixed) bug, though I don't think the fix is released quite yet.

See http://www.cfxchange.com/blog/post.cfm/coldfusion-9-air-orm-bug-memory-leak
Abram

Abram wrote on 03/09/10 4:20 PM

Just to note this bug has been verified and fixed. Don't know when it will be available to download though...

http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=81610
Shoop

Shoop wrote on 04/06/10 7:59 AM

Good to know the issue is fixed. Do you know if they already made it available for download?
Abram

Abram wrote on 04/06/10 2:27 PM

Not yet. I believe it is in the pre-release now. Not sure when they'll make it final.

Leave a comment

Tell us about yourself
(required field)
(required field)
Comment and preferences
Leave this field empty: