DataMgr is Better than ColdFusion ORM

I have been thinking this for some time, but it seemed like hubris (and flame bait) to say it. So be it - it needs to be said. I worry that ColdFusion ORM is being / will be marketed where it isn't appropriate.

(What is DataMgr?)

What is Better?

It can't be helped, "better" is a word that only makes sense in the context of goals to be met. After all, it is impossible to tell if a sedan is better than a truck unless you know your goals. Do you need to get to work on low gas mileage or haul cargo? I will use the criteria that Adobe ColdFusion engineer, Rupesh Kumar, has laid out in "ColdFusion ORM - An Evolution in building datacentric application":

[More]

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Interesting article here, but I think you are off on a few points:

"Hibernate (in particular) has opinions about table structure. If your table structure doesn't match how it things tables should be arranged, you have extra work to do."
Well sure. If you want to use firstname for a column instead of fstname, then you have to tell Hibernate what the 'real' column name is. But frankly, you would only do that to improve the code in general. Ie, if you think fstname is a bad name (we've all seen horrible table/column names) then defining the alias in HIbernate is a _good_ thing. It's worth the extra 'work' (2 seconds ;) to provide a cleaner, nicer column name. The fact that you can do this is a HUGE win for ORM imho.

"Development using an ORM is supposed to make you "stop thinking about the database". A fine thing except that most ColdFusion applications are all about the database."
Right, and that's a mistake that ORM can fix. Just because many CF apps have been 'all about the database' does not, and should not, mean it should _stay_ that way. Frankly I'd much rather be concerned with business logic than table names.

"The SQL doesn't execute immediately in Hibernate, instead executing at the end of a Hibernate "session" which almost matches a ColdFusion request. This means you have to start thinking about Hibernate sessions."
I agree with you here. This is something you have to be concerned about. Frankly it is the biggest issue I can see with going to ORM. However, I do think the benefits far outweigh the mild 'penalty' here of having to think about Hibernate sessions.

"Single Datasource"
Point taken - but I've rarely, if ever, used more than one DSN. And - you CAN use ORM if your site has 2-N DSNs, you just have to restrict the ORM usage ot one DSN. I believe in most cases where you have multiple DSNs, you still have one core DSN for most of your content, and other DSNs for auditing or security. So I'd just apply ORM to the main content DSN.

"If you are doing pure OO, then you should probably use an ORM."

I'm sorry, but OO has nothing to do with learning ORM. Just because you write a CFC to use ORM does not mean you are using OO. A person with no knowledge of OO at all can easily grasp the idea of: My component is a table, each property a column. Yes, you work with entities and methods, so you can consider this pretty light OO, but I don't think it is fair to say you must be using "pure" OO to use ORM. "Pure OO" means so many things to many different people, I don't think then this is a fair statement to make. You need not know nothing of design patterns or frameworks to write a simple CFC.
# Posted By Raymond Camden | 9/22/09 10:11 AM
I think the extra code segment sold me. I've been using dataMGR for quite some time now and with each presention of CF9's ORM features I keep coming back to, 'why, when we already have dataMGR with less code'.

Thank you for hammering this point.
# Posted By Mark | 9/22/09 10:38 AM
Ray,

Thanks for the feedback. I knew I was bound to miss on a few points. Always good to learn.

My statement about table structure had nothing to do with column names. It was really drawn directly from Ben Nadel's experience (I linked to his entry in that section).

As to thinking about the database, I definitely see your point but in CRUD apps it looks (to me) like the whole "you aren't supposed to think about the database" thing just makes life harder. I certainly don't think you think about table names any more with DataMgr than with ColdFusion ORM.

As to "If you are doing pure OO, then you should probably use an ORM.", you are definitely right. I really just meant that an ORM provides real advantage over a non-ORM DAL (like DataMgr) when you are doing "pure OO". Again, I agree that is a slippery concept and one I didn't want to tackle in this entry.

My point is that use of CFCs does not mean that you will get a savings out of ColdFusion ORM. Use of bona-fida objects, however, may.
# Posted By Steve Bryant | 9/22/09 10:50 AM
Mark,

Thanks for the kind words. That is exactly what I think as well (the impetus, in fact, for this entry).
# Posted By Steve Bryant | 9/22/09 10:51 AM
NOTE: My comment is being flagged as spam. Going to try to make this go through. UGH. What the heck?? Grrr. Now I'm getting mad. I'm going to try to post one part at a time.

About your code block, to be fair, if you used 4 lines to set sData values, then 4 lines to call the methods, I'd skip the sData step completely.
# Posted By Raymond Camden | 9/22/09 10:52 AM
This is part 2 to my last comment which I had to break out due to spam stuff.

I'd use code like this then, which takes out the unnecessary step of copying data to a structure.

cfset oContent.setFirstName(whatever)

At that point it becomes the same as DataMgr, right?
# Posted By Raymond Camden | 9/22/09 10:53 AM
Interesting post Steve.

Just for info, there is a error in your ORM code;

EntityLoad('Contact',sData.ContactID) will return an array of objects, in this case, an array with one element.
# Posted By John Whish | 9/22/09 11:57 AM
You can use EntityLoad('Contact',sData.ContactID, True) or EntityLoadByPK('Contact',sData.ContactID) to return an object.

P.S. I'm also being blocked as spam - hence the 2nd comment :)
# Posted By John Whish | 9/22/09 11:58 AM
Ray,

First of all, sorry about the spam trouble. I messed up a regular expression. I think I have that fixed now.

I used "sData" to avoid choosing a scope. Since every scope in ColdFusion can be treated as a struct, I think of this as one of the major strengths of DataMgr.

Normally I would use a saveContact method and use something like this:

Application.DataMgr.updateRecord("Contacts",arguments)

If you are going to have a bunch of "set" methods anyway, then I would argue that you may be in a situation where an ORM is a good match.

Even so, if you save all of those to variables.instance (for example), then you could still use:

Application.DataMgr.updateRecord("Contacts",variables.instance)

That is no more work that ColdFusion ORM (except that you don't need an EntityLoad call).
# Posted By Steve Bryant | 9/22/09 12:12 PM
John,

Thanks for the correction. I have corrected my entry accordingly.
# Posted By Steve Bryant | 9/22/09 12:16 PM
Point taken about the ability to pass in a struct. Of course, once could build a generic "set" for your CFCs in CF9 ORM. ;)
# Posted By Raymond Camden | 9/22/09 12:22 PM
Indeed they could. I linked to my friend Bob Silverberg's impressive Base Persistent Object project which includes that very functionality.

That still makes it 3 lines for ColdFusion ORM to 1 for DataMgr (not that reduction in lines of code alone makes for a superior solution).

It wouldn't surprise me at all if that made it into ColdFusion ORM before full release - making it closer to DataMgr ;)
# Posted By Steve Bryant | 9/22/09 12:31 PM
@RAY

When you say that a person with no OO knowledge can use Hibernate with no no matter at all you are completely wrong.
I am not talking of easy application to show how to save a record but I am talking about complex app that will require a huge OO understanding in order to manage hibernate properly.
Hibernate is the most huge JAVA framewrok I have ever seen and took me years to know that in a good manner....do not make it to easy cause is not.
# Posted By Andrea | 9/23/09 1:20 AM
@Ray - I don't know how common it is to use more than one dsn in an app, but all I know is that I have 5 DSNs for mine. An adobe tech gave me the same workaround you suggested about using the ORM for the "main" one. But come now, that is clearly a major hack. Who would want to have that? I have used a couple of ORMS in the .net world and they both had built-in support for multiple DSNs. How hard can it be? In my opinion, the fact that Adobe has left this out is a "deal breaker" for me, and I would assume anyone else who has multiple DNSs in their app.

@Steve - Thanks for the comparison. I know that we (DataMgr users) are in the minority, but I believe the DataMgr concept is a seriously good alternative approach to any ORM solution - especially the CF ORM.
# Posted By Randy | 9/23/09 7:44 AM
Andrea,

In fairness, I think Ray was just saying that you don't have to use "pure" OO in order to use ColdFusion ORM. Even so, I agree that ColdFusion ORM looks (based on several blog entries that I have read) to be more difficult to learn and use for real-world development that it at first appears.

Randy,

Thanks. I'm sure it won't surprise you to learn that it was you I was thinking of when I mentioned the single datasource restriction.
# Posted By Steve Bryant | 9/23/09 1:11 PM
A single datasource is a complete deal breaker for me even if I do not plan to use multiple DSNs.

I had considered using the CF ORM on my next project but that is off the table if I can only use one DSN. There are plenty of valid reasons for more than one DSN on a single application. What if I have more than one server (i.e. some data in MSSQL and some data in MYSQL)?

I really like Coldfusion, but it seems whenever a new features is added it is also crippled in someway. CFREPORT anyone?

Adobe usually updates/fixes this later, but why release half of a feature?

If I've read this thread wrong and multiple datasources are possible then please correct me.
# Posted By Jason Holden | 9/23/09 4:35 PM
Hey Steve, thanks for the links! I somehow missed this entry when you posted it. :)

I was actually looking for your CF DAL/ORM comparison entry because I just pushed a version 1.1 Release Candidate of DataFaucet with the new persistence service feature, which means it's no longer a BER feature (like it says in that comparison chart).

From the looks of it, the persistence service in DF will be significantly simpler than the Hibernate integration in CF9. Honestly, I'm mildly surprised at how complicated the new Hibernate features look. The Hibernate sessions thing is the wierdest one imo and liable to cause the most confusion and problems in the long-run... at least of what I've seen. What happens if there's an error on the page? Does the Hibernate session still execute its changes or does it abandon them? I could see either choice causing headaches. DataFaucet has no "sessions" concept, it just updates the datasource as soon as it can. Which is immediately for relationships on previously saved objects, or as soon as the object is saved otherwise. The convenience of structure population is built-in to the save() method (much like the rest of DF), and multiple DSNs have been supported since the very beginning. ;)
# Posted By ike | 10/8/09 1:47 AM
Take 2 for Spam Filter ;)

It does currently have the N+1 problem though... I may go back and tweak it so that the getArray() method uses a single query to populate all the non-cached objects in the array instead of querying for each one. It may be slightly challenging, but it should be possible. The challenge has more to do with working the reads around the possibility that some of the objects in the array may already be cached.

Anyway there's a blog about the new release here: http://datafaucet.riaforge.org/blog/index.cfm/2009...

And the documentation for it is up on the DF site here: http://www.datafaucet.com/persistenceservice.cfm

I've been having fun playing around with the maze game I created as a sample application. :)

Oh and I got this weird error from your "contact us" form on the Bryant Web Consulting website... I think you used a cfcatch with an "any" type instead of a custom type for your form validation. It says "We're Sorry. Some information is missing or incomplete: The CHECKCASE argument passed to the numRegExMatches function is not of type boolean." Didn't seem like something I could fix by changing the form inputs. ;)
# Posted By ike | 10/8/09 1:48 AM
Ike,

Thanks for the heads up on DataFaucet 1.1. I have been a bit busy and so I haven't kept up with the outside world very well.

I think many CF project do not need ORMs. For the many that do, however, I still think that they should investigate options such as DataFaucet and Transfer for just the reasons you mentioned.

Sorry about the spam filtering. I am planning to redo that in the near future. Contact form is fixed now - thanks for the heads up on that.

I did update the DAL Comparison page. Let me know if I missed anything and I will correct it.
# Posted By Steve Bryant | 10/9/09 2:01 PM
Steve, and all
not only scopes, forms etc are structure: i pass the memento of any instance of any class in my project, the table which such instance is to be
persisted in, and your dataMgr save it: too simple!
i use a generic data layer, with an instance of dataMgr injectd, with a numbr of methods: ie, i simply pass a bean and a table as arguments to these and all is done.
dataMgr is a great tool.
salvatore
# Posted By salvatore fusto | 10/12/09 9:42 AM
Thanks Salvatore!
# Posted By Steve Bryant | 10/12/09 9:10 PM
Steve this so rocks... You did a great job with this!

I just rolled datamgr into my rig (kinda like datamagr.... 'cept I use an abstract service cfc in front of the default Illudium templates). It took me a whole 15 min to swap out an Illudium based back end to Datamgr...

Dude! This is insane. I just swapped out my entire database layer in 15 min. OOP's. (pun intended) Gotta love it.

I am running datamgr on Railo OS and it is *disturbingly* fast. Thanx for taking the time on that!

G!
# Posted By Gerald Guido | 12/6/09 12:16 AM
Gerald,

Thanks! I would guess some of ease you found was due to how well Brian architected Illudium, about which I have heard nothing but good things.
# Posted By Steve Bryant | 12/6/09 10:50 AM
The fact that datamgr works with Railo is going to be a definite plus for me. I can't seem to find a lot about Railo having the built in ORM that cf9 has, does anybody know if this will ever get developed? or has been developed?
# Posted By Matt | 7/20/10 5:53 AM
Good post filled of useful tips! I love how you have written it properly but purposely. I have learned a lot from you. Awesome job and more writings to come!
# Posted By sinotruk | 9/21/13 8:41 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.