Search code examples
hibernateormcoldfusioncoldfusion-9

ColdFusion ORM mappedSuperClass .hbmxml has too many fields


When I run the code below, ColdFusion 9 (updated to latest) generates a wrong (imho) XML file for the billingaddress cfc. Namely, it includes the properties of base.cfc. Is this a bug, am I missing something, or is this expected behavior?

Application.cfc

component
{
  this.name = "ormtest";
  this.mappings["/model"] = expandPath( "./model" );
  this.datasource = "mingo";
  this.ormEnabled = true;
  this.ormSettings = {
    CFCLocation = "/model",
    dbcreate = "dropcreate",
    savemapping = true
  };

  function onRequestStart()
  {
    ormreload();    
  }
}

base.cfc

component mappedSuperClass = "true"
{
  property fieldType = "id"     name = "id" generator = "guid";
  property fieldType = "column" name = "deleted" ORMType = "boolean" default = "0" notnull = "true";
  property fieldType = "column" name = "sortorder" ORMType = "integer";
  property fieldType = "column" name = "label";
}

address.cfc

component extends = "model.base"
          persistent = "true"
          table="address"
          discriminatorColumn = "discriminator"
{
  property name = "address";
}

billingaddress.cfc

component extends = "model.address"
          persistent = "true"
          table="address"
          discriminatorValue = "billingaddress"
{}

billingaddress.hbmxml

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <subclass discriminator-value="billingaddress"
        entity-name="billingaddress" extends="cfc:model.address"
        lazy="true" name="cfc:model.billingaddress">
        <property name="deleted" type="boolean">
            <column name="deleted" not-null="true"/>
        </property>
        <property name="sortorder" type="integer">
            <column name="sortorder"/>
        </property>
        <property name="label" type="string">
            <column name="label"/>
        </property>
    </subclass>
</hibernate-mapping>

Solution

  • That's the behavior I would expect. Extending a component will cause the child to inherit the parent's properties. When you have multiple levels of inheritance, it will inherit all the way back up the chain.

    After reading your comments, I looked into this a little further. As far as I can tell, the problem you're describing first showed up in CF9 Cumulative Hot Fix 2, probably (just guessing here) as a result of this bug fix:

    ColdFusion ORM does not maintain the column order correctly when the CFC extends a base cfc with an attribute mappedSuperclass set to true.

    The bug referenced is #83474, which I can't seem to find on Adobe's bug tracker. It's mirrored on Elliot Sprehn's site, here.

    I also found another question here on SO regarding the same problem: Wrong HBM mappings when using a mapped superclass in an inheritance graph for ColdFusion 9.0.1 Hotfix 2. The workaround reported in that question is to manually edit the hbmxml files.

    Long story short, it looks like a CF bug. I poked at it for about 20 minutes and was unable to find a workaround other than manually editing the hbmxml files to remove the extra properties from billingaddress.cfc.