EntityToQuery behavior in Railo and ACF

This post concludes a long and painful story of porting a complex ACF/Hibernate application to Railo. As usual 99% of the code worked flawlessly, it was that 1% that puzzled me a lot. Let’s take a look at one of the problems I encounter.

Components

User.cfc serves as a superclass for CompanyUser.cfc, VendorUser.cfc and CustomerUser.cfc components. All these subclass components are persistent. They all extend the User.cfc component which is persistent as well.

 
component persistent="true" table="User" name="User" displayname="User"  
 
{
  property name="UserID" fieldtype="id" ormtype="integer" generator="identity";
  property name="admin" fieldtype="column" ormtype="int";
  property name="active" fieldtype="column" ormtype="int";
  property name="confirmed" fieldtype="column" ormtype="int";
  property name="country" fieldtype="column" ormtype="int";
 
.....
 
  public numeric function getVersion() { return 1; }
}

All subclass components are organized in a similar way:

 
component persistent="true" table="CustomerUser" name="CustomerUser" displayname="CustomerUser" extends="User" joinColumn="UserID" 
 
{	
  property name="firstName" ormtype="string" fieldtype="column";
  property name="infixName" ormtype="string" fieldtype="column";
  property name="lastName" ormtype="string" fieldtype="column";
  property name="initials" ormtype="string" fieldtype="column";
  property name="role" ormtype="integer" fieldtype="column";
 
.....
 
  public numeric function getVersion() { return 1; }
 
}

We are using ACF 9.0.1 and Railo 3.3.3 with MySQL 5.5.14

The problem

The dumps of the subclass entities look similar in ACF and in Railo. You can iterate through the arrays of objects and access all underlying methods of the superclass. The fun begins when you apply the EntityToQuery method to the arrays of subclass objects. Let’s take a look at the same code in ACF and Railo:

  var _customerUserArr = EntityLoad("CustomerUser");
      _customerUserQry = EntityToQuery(_customerUserArr);
 
  writeDump(_customerUserQry);

The output is radically different: where ACF shows the properties of the superclass as query columns, Railo ignores them altogether:

ACF 9.0.1

Railo 3.3.3

Please note that ACF as well as Railo allow you to provide the object type as a second argument to the EntityToQuery() method but I couldn’t get it working in Railo as it kept throwing the stack overload error.

That behavior renders EntityToQuery() unusable if you intend to keep your application fully compatible with those both CFML engines.
I’ve tried to re-architect the application using non-persistent superclasses with the MappedSuperClass setting set to true but that involved too much refactoring and I decided against it. The solution is easy and obvious: just do not use the EntityToQuery() method in your application, use the object getters instead even if it makes the life of the front-end developer who is used to insert query column names where necessary more complex. It is cleaner and it saves you hours of debugging time.

Have fun!