ColdFusion ORM is far to complicated than it has to be.
Tags: Coldfusion
One of the most anticipated features of ColdFusion is the hibernate integration that has been introduced, however the one problem is that even though it is very flexible, it's also very complicated to understand and get working.
It would have been nice that the minimal things needed to get some relationship mapping happening, have been thought about.
When doing relationships with our tables, we have one to one, one to many and many to many. And trying to map this in a persistent component in ColdFusion should have been made a lot easier that it is.
So lets have a look at how ColdFusion does it now if you want to do a one to many relationship.
However simple it looks it is still way to over complicated, and the user should not have to define all these extra things. Only if they want to get under the basic implementation and expand on it, should a developer have to give that much detail.
What should have been implemented is something like this.
And that would have been enough to have a one to many relationship setup from the developer, and ColdFusion could do the rest.
The beauty about the shorter version is it is clear that the property has many art objects, and that we are not having to worry about the type or setting the field type, or even the foreign key. All of this information could be taken care of under the hood and let the developer get on with writing code in a faster and easier manner.
Using hibernate in ColdFusion is going to be complicated to the average developer, and why ColdFusion makes it even harder is beyond me. But lets hope that we can push to make it simpler in the very next release.
The notion that as a developer to create a one to one relationship you have to define the following in both persistent components, which neither should have to do at all.
<cfcomponent persistent="true" table="Employee">
<cfproperty name="EmployeeID" fieldtype="id" generator="native">
<cfproperty name="firstname"> <cfproperty name="lastname">
<cfproperty name="officecubicle" fieldtype="one-to-one" cfc="officecubicle" mappedby="Employee">
</cfcomponent>
OFFICECUBICLE.cfc
<cfcomponent persistent="true" table="officecubicle">
<cfproperty name="id" fieldtype="id" generator="native">
<cfproperty name="Employee" fieldtype="one-to-one" cfc="Employee" fkcolumn="EmployeeID">
<cfproperty name="Location"> <cfproperty name="Size">
</cfcomponent>
I mean it would be nicer to have to just write.
<cfcomponent persistent="true" table="Employee">
<cfproperty name="EmployeeID" fieldtype="id" generator="native">
<cfproperty name="firstname"> <cfproperty name="lastname">
<cfproperty name="officecubicle" hasOne="officecubicle">
</cfcomponent>
OFFICECUBICLE.cfc
<cfcomponent persistent="true" table="officecubicle">
<cfproperty name="id" fieldtype="id" generator="native">
<cfproperty name="Location"> <cfproperty name="Size">
</cfcomponent>
Anyway I hope Adobe look at this as way to much work, complicated to understand as it currently stands in ColdFusion and look at making it a lot more simplistic than they have made it.
-
Given the alternative (not having ORM), do you really think '<cfproperty name="art" type="array" fieldtype="one-to-many" cfc="Art" fkcolumn="ARTISTID">' is too complicated? Really?
# Posted By SCott Stroz | 11/2/09 5:46 AM -
Yes I do.
Adobe made it very clear that certain aspects of the ORM functios were introduced for that reason, they wanted to simplify it.
I think Adobe could have simplified it more, and I hope that the next release they do.
# Posted By Andrew Scott | 11/2/09 10:50 AM -
I'm afraid your version does not have enough metadata for hibernate to work with.
e.g. hasOne = one-to-one or many-to-one?
Also, I think adobe chose to use same/similar metadata that hibernate defines, so that ppl who knew hibernate can pick up CFC's metadata syntax easier. -
I think you'll find there is more than enough information Henry, Grails has been able to do it this was for years.
So my logic is very simple, if an ORM that has been around long enough, can do it then ColdFusion is more than capable of doing it.# Posted By Andrew Scott | 11/2/09 7:09 PM -
Since type and fkcolumn are optional, you only need to define it like
<cfproperty name="art" fieldtype="one-to-many" cfc="Art">
Is that too complicated than your idea? I will leave it to people to decide :-)
# Posted By Rupesh Kumar | 11/4/09 10:14 PM -
The thing is Rupesh all the examples in the documentation don't show it as being that easy, all the docs show that we have to define a relationship on both entities, and yet it doesn't or should be that complicated.
We should only need to do it on one entity, and when we do the following error is what is thrown.
Error while resolving the relationship pages in cfc domains.system.space. Check the column mapping for this property.
# Posted By Andrew Scott | 11/5/09 9:30 AM



TweetBacks