ORM vs. SQL in ColdFusion, which is better?

{ Posted By : Eric Cobb on October 4, 2010 }
2350 Views
Related Categories: ColdFusion

This morning I was reading through Marcos Placona's review of John Farrar's ColdFusion 9 Developer Tutorial. When talking about the chapter on ColdFuion's built in Hibernate ORM functionality, he said something that really seemed to jump out at me.

"ORM really seems magical, and will do wonders for small to medium projects, where high performance is not the major concern."

What really struck me about that comment is the suggestion that for really high performance applications you may not want to use CF's ORM. I had not considered this. I'll admit that I know very little about ORM, and have never done anything with it. I want to, but just haven't had the chance. I've got an idea for one of my personal projects that I want to start on soon, and I was planning on using ColdFusion's built in ORM for it. But, now I have to wonder, is it the right choice for my application?

This really got me to thinking, at what point does your application outgrow ORM? (or does it?) If you were building an application that's going to be large scale, high traffic, with millions of DB transactions per day, would you use ORM or avoid it favor of something else?

Since I know so little about ORM, I wanted to reach out to the community to get some opinions. Is ColdFusion's built in Hibernate ORM better suited for smaller-to-mid sized applications than larger high traffic applications, or can it handle anything you throw at it?

Comments
Andy Jarrett's Gravatar I've only used ORM for small/med projects but for my larger projects I pass a lot of heavy SQL over to Stored Procedures. I also like knowing that I have a lot of granular control at the DB level. Im not saying ORM doesn't give this ( I haven't had the real time to dive in) but in my head its another layer in-between the me and the data.
# Posted By Andy Jarrett | 10/4/10 11:22 AM
Rob Dudley's Gravatar Whilst I can't claim to be an expert in ORM and may get shot for offering this moderately unfounded opinion I'd suggest that ORM scales as well as anything "easy" in the ColdFusion world.

Looking at the Hibernate config options you have under the hood I should imagine it's possible to scale it out quite well especially with clusters of app and db servers running alongside good caching services and other must have tools for high traffic / throughput apps.

When scaling any app you've got to look at which aspects of the whole range of servers and services are slowing you down / bottlenecking and Hibernate has a lot of very clever caching and performance enhancing attributes out of the box that would take quite some effort to replicate in a home brew DAL. Yes in theory non ORM sites should be faster but that requires a good understanding of DBA and SQL optimisation (also needed for ORM) and requires a lot more work to maintain.

Like anything it comes down to how well you can design and understand the limitations of the tool set when developing the architecture for your app and that applies equally with ORM or without.
# Posted By Rob Dudley | 10/4/10 11:38 AM
Henry's Gravatar evaluate ORM's strength and weaknesses, and use a mix of them. As always, it depends, right? :)
# Posted By Henry | 10/4/10 1:37 PM
Eric Cobb's Gravatar @Andy - I'm with you on the Stored Procedures. I've always been a big fan of letting the database do the database work. That's a good point about Hibernate adding another layer, I hadn't considered that.

@Rob - I've heard a lot of good things about Hibernate and figured it was tweaked and had, as you said, "a lot of very clever caching and performance enhancing attributes out of the box". That's why I was so intrigued when I read Marcos' comment. I personally have always assumed the ORM performance would be on par with or better than running plain 'ole SQL queries via CF.

@Henry - good point. I can definitely see mixing ORM and Stored Procs/SQL for certain things.
# Posted By Eric Cobb | 10/4/10 3:20 PM
Andrew Scott's Gravatar ORM can scale very well, and can be used in extremely high performance sites.

The problem is the exact same problem can occur without ORM in standard queries as well.

Just like a badly written SQL Query can be bad, so can a badly written Domain Model.
# Posted By Andrew Scott | 10/4/10 8:12 PM
Andrea's Gravatar ORM is done for very large systems. There is no reason to use it for a 10 tables project.
I never saw hibernate implemented on a small project in my life. Point is not prerformance ( you always can pump more power ) but scalability. Orm = scale ; Sql = no scale

:)
# Posted By Andrea | 10/5/10 1:43 AM
Andrew Scott's Gravatar I have seen hibernate used in small to very large enterprise solutions, all of which were grails applications.

And I am personally using CF-ORM in a small scale application right now with around 6 tables, but I expect this to scale to more tables and hopefully a larger project over time.
# Posted By Andrew Scott | 10/5/10 2:28 AM
tom chiverton's Gravatar @Andrea there are many reasons to use an ORM in a small project, not least the time saved by not having to write the same repetitive SQL over and over again (ten times in your example).
# Posted By tom chiverton | 10/5/10 4:02 AM
Rob Dudley's Gravatar @Andrea - I've used ORM for small projects only at this point as haven't had the time to work out how to address the requirements of some of our larger projects within the confines of Hibernate configuration. That said I agree that it afford the potential for major scalability if correctly implemented.

@Eric - a further assumption but once you reach a certain level of required throughput then it may be simpler to manage and maintain DB IO without ORM. Of course by the time you get to that point (I'm thinking Twitter-esque scale) you would have whole teams of DBAs ensuring your data layer is as performant as humanly possible. You also have other concerns for larger enterprise apps (reporting and data mining ability, OLAP etc.) which may introduce requirements that render ORM unsuitable.

I would be interested to see if anyone has examples of large scale CF apps running on ORM and if they can offer any insight into the pros and cons.
# Posted By Rob Dudley | 10/5/10 4:12 AM
Eric Cobb's Gravatar @All - Thanks for the comments! This exactly the discussion I had hoped to get out of this post. I'm getting some excellent insight from you guys!
# Posted By Eric Cobb | 10/5/10 9:05 AM
Aaron Greenlee's Gravatar My experience is that ColdFusion's ORM implementation supports millions of unique users/page views a month just fine. You do need to understand the "magic" and implement things like the second-level cache.
# Posted By Aaron Greenlee | 11/4/10 11:54 AM
Eric Cobb's Gravatar @Aaron - Thanks, that's good to know. Do you have any recommended documentation/articles that help explain the second-level cache "magic"?
# Posted By Eric Cobb | 11/4/10 1:24 PM