Aliaspooryorik
ColdFusion ORM Book

ColdFusion v Railo ORM

I've been working on an ColdFusion 9.01 ORM application so that it also runs on Railo 3.3.1 and found a few differences which I thought I'd blog in case it helps anyone else.

The biggest one for me is that Railo does not support automatic dirty checking.

This means that if I have an application which is setup so that the ormsettings.flushatrequest setting is false (which I think everyone agrees is the best practice). Then this code in ACF will save the modified persistent Entity, in Railo it will not.


transaction
{
Foo = EntityLoadByPK( "Foo", 1 );
Foo.setBar( "ABC123" );
}

In ColdFusion, closing the transaction will cause any "dirty" entities to be committed to the database. This is the normal behaviour in Hibernate. Railo does not commit the changes at all.

To make it work in Railo is pretty simple, just add an EntitySave call (EntitySave is only required to save non-persisted entities in ACF). So the code now looks like:


transaction
{
Foo = EntityLoadByPK( "Foo", 1 );
Foo.setBar( "ABC123" );
EntitySave( Foo );
}

You could also use ORMFlush() to force the changes to be commited but I think EntitySave is a much better approach as ORMFlush() will cause any dirty entities in the session to be committed. You can view my ticket here.

Another thing I found was that in Railo you don't need to specify the full path to other entities for relationships. For example in ACF I need to do this to map a relationship between two entities in different packages (folders).


property name="bars" fieldtype="one-to-many" cfc="model.foo.bars";

In Railo I can do this:


property name="bars" fieldtype="one-to-many" cfc="bars";

This makes a lot of sense to me as entity names are unique and EntityLoad etc don't require the full path, however, if you had a complex application I would probably put the full path in for clarity.

I did also have some issues with passing entities into HQL queries but the tickets I raised seem to be fixed now.

Looking through the other tickets on the Railo bugtracker, there are some other incompatibilities, such as multiple datasources and embedded mappings, but the Railo guys do seem to be pretty quick at resolving issues.


5 comments

  1. Does Railo ORM save related entity updates when save is called on a entity all the time?

    Comment by John Farrar – December 22, 2011
  2. You mention: "(EntitySave is only required to save non-persistant entities in ACF)".

    Saving non persistant entities? Can you clarify this a bit?

    Comment by John Allen – December 22, 2011
  3. Say you update details on a shopping car record, and update details on cart items (nested relation) entities in the same request. In Railo can you update the cart entity and it will automatically save the related changed items also? Will you need to update everything everywhere?

    Comment by John Farrar – December 22, 2011
  4. "Saving non persistant entities? Can you clarify this a bit?"

    By 'non-persistent' I think John is referring to an object that has not yet been saved to the database.

    Comment by Simon Bingham – December 22, 2011
  5. @John F, the cascading works, I think it's just that Hibernate doesn't know that the entity has been updated.

    @John A, sorry for not being clear. By "persistent entity" I mean an entity that has been retrieved from the database (via ORM), a non-persistent entity is one that is new and hasn't (yet) been committed to the database.

    Comment by John Whish – December 22, 2011

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.

Please subscribe me to any further comments
 

Search

Wish List

Found something helpful & want to say ’thanks‘? Then visit my Amazon Wish List :)

Categories

Recent Posts