Recently, I've been diving heavily into the ORM integration that Adobe has provided the ColdFusion developers with... Having had experience with Hibernate proper (directly in Java), I dove into this knowing what should be possible with the ORM and what shouldn't. Today, I ran into a rather troublesome bug. In short - I found that when serializing to json a persistent ColdFusion components that extends another persistent component, only the properties defined on the concrete object are included in the JSON... This prevents the reuse of objects and forces ColdFusion developers to keep the depth of inheritance for persistent objects to 1 (excluding mapped super classes). Today - I'd like to present this bug to you.
To demonstrate the issue, We'll use ColdFusion's common example as a basis. Let's imagine that we have a base object class known as Payment, and two siblings known as CreditCardPayment and CheckPayment. CreditCardPayment will also be extended by VisaPayment. The relationships can be illustrated as such:

And the code for the objects are is as follows:
Payment.cfc
<cfcomponent persistent="false" mappedSuperClass="true" table="Payment" discriminatorColumn="paymentType" >
<cfproperty name="id" fieldType="id" generator="assigned" insert="false" update="false">
<cfproperty name="amount">
</cfcomponent>
CreditCardPayment.cfc
<cfcomponent persistent="true" extends="Payment" table="Payment" discriminatorValue="CCard">
<cfproperty name="cardNo">
</cfcomponent>
VisaPayment.cfc
<cfcomponent persistent="true" extends="CreditCardPayment" table="Payment" discriminatorValue="VisaCCard">
<cfproperty name="cvv">
</cfcomponent>
CheckPayment.cfc
<cfcomponent persistent="true" extends="Payment" table="Payment" discriminatorValue="check">
<cfproperty name="checkNo">
<cfproperty name="bankName">
<cfproperty name="city">
</cfcomponent>
So now that we've got the code to create our objects - lets create an object and demonstrate the fault in ColdFusion's serializeJSON() method.
<cfscript>
p = EntityNew("CreditCardPayment");
p.setId(1);
p.setAmount(1200);
p.setCardNo("123451234561234561345");
EntitySave(p);
ORMFlush();
WriteOutput(SerializeJSON(p));
</cfscript>
We get the following output for the example above:
{"cardNo":"123451234561234561345","id":"1","amount":"1200"}
Which is correct. But when we create a VisaPayment, and serialize the response, take a look at our serialized JSON.
<cfscript>
p = EntityNew("VisaPayment");
p.setId(1);
p.setAmount(1200);
p.setCardNo("123451234561234561345");
p.setCVV(123);
EntitySave(p);
ORMFlush();
WriteOutput(SerializeJSON(p));
</cfscript>
{"cvv":"123"}
I've tracked down the problem - and the problem is within the coldfusion.runtime.JSONUtils class within the ColdFusion core. I won't say that I decompiled coldfusion and made a fix - but I will say that it appears as though when ColdFusion serializes an object (in this case, a TemplateProxy), it doesnt take into consideration that not all properties have to be defined directly on the object itself, and may come from a parent persistent object or mappedsuperclass. Hopefully this is something that will be fixed in ColdFusion Zeus.