Over a million developers have joined DZone.

Some Things About MappedSuperClass in ColdFusion 9.0.1

· Java Zone

Navigate the Maze of the End-User Experience and pick up this APM Essential guide, brought to you in partnership with CA Technologies

I was fooling around with inheritance in super classes in ColdFusion 9.0.1. I was trying to add that whole dynamic/static inheritance thing to Apptacular so you can add on to an Apptacular application without having to worry about changes being overridden by the regeneration process. Typically when you do that, the dynamic, rewritten class is usually the parent of the child static class. The child, static, class is what you refer to in the rest of code and in which you write custom code. The scaffolder never touches this file again, allowing you to alter things in the database, rescaffold and not overwrite code customizations. I hearby call this "non-destructive scaffold regeneration," regardless of what other people call it.

ORM entities can't really work that way. If you try to setup that sort of thing, ORM craps out in ColdFusion with an error. CF9 ORM doesn't really like ORM objects being the parent of other items, unless you are using inheritance mapping.

However, if you use the "mappedSuperClass" cfc attribute that is now available in ColdFusion 9.0.1 you can achieve sort of the same thing, but you have to flip this on its head. The superclass is the one that is static, and you can edit, while the dynamic one is the child.

This is mostly good. Except for one thing: one of the main reasons to write code this way is so you can override methods, and if the child is the one that is dynamic, and overwritten, then you cannot override the methods from the static parent. You can add methods and properties, but you cannot override them.

At first glance this seems like a deal breaker, but it doesn't have to be. Most generated ORM entities are light on code, because of implicit getters and setters. But those implicit getters and setters are exactly what you want to override in an ORM entity. However it turns out that explicit functions will always override implicit ones, even when the explicit function is in the super class and not the child class.

I put together a simple little demo to show this off:

component mappedSuperClass="true"{
	public string function getFirstName(){
		return "Yo";
	public string function getRealFirstName(){
		return variables.firstName;
	This.name = "cfartgallery";
	This.ormenabled = true;
	This.datasource = "cfartgallery";
component extends="_artistsSuperEntity" persistent="true"{

	property name="ARTISTID" fieldtype="id" ;
	property name="FIRSTNAME" type="string";
	property name="LASTNAME" type="string";
	property name="ADDRESS" type="string";
	property name="CITY" type="string";
	property name="STATE" type="string";
	property name="POSTALCODE" type="string";
	property name="EMAIL" type="string";
	property name="PHONE" type="string";
	property name="FAX" type="string";
	property name="THEPASSWORD" type="string";	
<cfset artist = entityLoad("artists", 1, true) />
	<p>GetFirstName = #artist.getFirstName()#</p>
	<p>GetRealFirstName = #artist.getRealFirstName()#</p>

Result from test.cfm:

GetFirstName = Yo

GetRealFirstName = Aiden

So it's a little upside down, but if you want to do some non-destructive scaffold regeneration with ColdFusion 9 ORM, it's a workable solution. E

Thrive in the application economy with an APM model that is strategic. Be E.P.I.C. with CA APM.  Brought to you in partnership with CA Technologies.


Published at DZone with permission of Terrence Ryan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}