ColdFusion ORM: A Guide To Developing Applications Using ColdFusion ORM By John Whish

Posted October 31, 2011 at 10:05 AM by Ben Nadel

Tags: ColdFusion, Books

Over the weekend, I finally got to read ColdFusion ORM: A Guide to Developing Applications Using ColdFusion ORM by John Whish. With the release of ColdFusion 9, Adobe has fully integrated Hibernate - the industry leader in Object Relational Mapping (ORM) - into the core language. With the release of the ColdFusion updater - 9.0.1 - a number of critical differences were made to the Hibernate implementation. ORM is some hard stuff! Not only does it require you to change much of how you think about building applications, ORM, in and of itself, is a tricky beast. Luckily, this book masterfully ties it all together in an easy to understand, tangible set of examples and explanations.


 
 
 

 
ColdFusion ORM: A Guide To Developing Applications Using ColdFusion ORM By John Whish. Review by Ben Nadel. 
 
 
 

If you've followed the Object Relational Mapping (ORM) technology emerge in the ColdFusion world, you've probably seen a number of super smart people stumble over the caveats of ColdFusion's integration with the underlying Hibernate engine. This is because ORM is complicated; everything from the session management to bidirectional relationships to lazy loading needs to be understood in order for your application to run optimally and as expected. Missing even little things like the "inverse" attribute can end up leaving you with unsaved data and possible runtime errors.

Don't let me scare you off, though; Object Relational Mapping (ORM) is a powerful tool. And, the ColdFusion ORM API does a wonderful job of simplifying the vastly complex functionality and configuration of the underlying Hibernate engine. It's just that, with this technology, the devil is in the details. In ColdFusion ORM, John Whish takes you through building a Blogging application, one ColdFusion component at a time. With each CFC, he explains how to set up persistence, configure the synthesized getters and setters, define the relationships, and optimize the generated SQL statements for performance.

Reading this book will leave you with an excellent understanding of the ORM landscape. It will not, and was not intended to, replace the ColdFusion documentation; but, it will give you a mental model of how the entire ORM world comes together. This includes how to configure every part of your application, when and how to use the features of HQL (Hibernate Query Language), and when to rely on plain old SQL statements. If you're getting into ORM, this is definitely a book you should read.



Reader Comments

Oct 31, 2011 at 10:48 AM // reply »
8 Comments

Ben,

Completely off-topic (sorry) but I noticed you wearing a Mura shirt. I've toyed with Mura but haven't built a full-fledged site with it yet. I'd love to read some articles on your experiences with it if you ever find the time.

Great blog. Thanks!


Oct 31, 2011 at 11:09 AM // reply »
7 Comments

Gonna have to give this a read. I have a large project which we started intrgrating ORM into. I started learning the hard way wait CF 9.0, it'd be nice to have some independent confirmation I'm thinking the right way.


Oct 31, 2011 at 11:11 AM // reply »
7 Comments

God, sorry for all the tyops in my previous post. It's definitely Monday morning!


Oct 31, 2011 at 11:13 AM // reply »
1 Comments

Based on what you've read/experienced, what do you think is the most influential criteria in deciding whether or not to implement ORM in your application?


Oct 31, 2011 at 11:41 AM // reply »
2 Comments

I tried to buy the PDF version, but the stupid folks at PayPal decided not to take my US, my UK or my Belgium debit card??. FANTASTIC

I hope to be able to get my hands on the book soon


Ken
Oct 31, 2011 at 12:46 PM // reply »
10 Comments

Awesome! I've been wanting to learn this but didn't know where to start. Looking through the CF documentation, I always had questions about how things were working in the background to maintain the data, but I'll definitely give this a look based on your description!


Oct 31, 2011 at 7:52 PM // reply »
3 Comments

Glowing words of praise to be sure but let me ask a quick little follow up question. How would this read for someone who currently knows nothing about ORM? As in would this be a good book to purchase to get into it starting from nothing or is there something I should read in between?


Nov 1, 2011 at 10:02 AM // reply »
39 Comments

Thanks Ben!
I think for the price of going to a conference, one could buy every ColdFusion book that's currently in print.


Nov 2, 2011 at 6:09 PM // reply »
31 Comments

I'm working on my website at home in CF9, and am very interested in taking full advantage of ORM and Hibernate, however, he doesn't seem to offer a free chapter or even some sample pages.


Nov 3, 2011 at 10:10 AM // reply »
11 Comments

Firstly, thank you Ben for posting your review - especially as you seem to like the book!!! :)

I hope people don't mind me posting answers to their questions...

@Justin - adopting CF ORM or any new way of working is painful at first, but once you've got the hang of it then I believe it is well worth investing the time. I also think that even if you don't decide to use a new technology you can often learn a lot just by trying it out.

@Darrin - are you still having trouble?

@Joseph - The book starts by talking about how to configure it and a brief background to what it is and does. If you are familiar with ColdFusion then I don't think you'll have any problem following along. Most things are demonstrated with code samples.

@Aaron - I haven't really thought about a free chapter. If you've ever read my blog then hopefully you'll get an idea of my writing style. There is actually a generated preview on the Lulu site if you hit the "preview" link on: http://www.lulu.com/product/paperback/coldfusion-orm/18465758

Thank you all for your interest!!

- John


Nov 3, 2011 at 2:18 PM // reply »
11 Comments

Thanks as always Ben - I'll be reading this over the weekend.


Nov 3, 2011 at 6:19 PM // reply »
31 Comments

@John-

I appreciate the link, however the preview just provides prefaces, special thanks and a table of contents; there's no actual content or writing style to evaluate.

I may just take the plunge. I really want a firm understanding of ORM, and after skimming through the topics in the ToC, if it can teach those things, I think I'll be able to hit the ground running.


Nov 4, 2011 at 5:28 AM // reply »
11 Comments

@Aaron - I've been playing around with the preview on the Lulu site and have managed to get it show the first chapter if you are interested. Feel free to hit me up if you have any other questions so that I don't hi-jack Ben's blog :)


Nov 4, 2011 at 8:05 AM // reply »
31 Comments

@John-

Thanks for providing a free chapter! Gonna give it a read right now!


Nov 7, 2011 at 10:30 AM // reply »
11,238 Comments

@PMascari,

I've not really tried Mura myself. But I've seen a few presentations and talked to some people who use it regularly. It looks awesome. And the people who build CMS's with it say that it's super easy to use and very powerful.

@Joe,

You never have to worry about typos with me :) I'm convinced my poor spelling is a genetic trait ;) I've got your back!

@Justin,

That's an excellent question. I, personally, still struggle to wrap my head around some of the more complex Object Oriented concepts (I have some irksome mental blocks with all this stuff). I think the hardest part for me is just learning to think in terms of objects from the very beginning and NOT from the point of view of the database.

That said, the people that I talk to that use ORM on a regular basis tell me that they would never do an app any other way going forward. So, perhaps the question is not IF you should use ORM; perhaps the question is really where in a given app ORM helps and where you should be deferring to HQL or SQL for querying purposes.

Sorry my answer is not more definite; I'm still on ColdFusion 8 for most things, so I haven't taken the full plunge into ORM just yet.

@Darrin,

Yikes, that sucks :( Sorry to hear that.

@Joseph,

Great question! I think this book would read really well. As long as you know how ColdFusion components work, this book should be good. I don't know very much about ORM at all. I think on my site, I have maybe 2 posts about ORM. I'm still mostly on CF8, so I don't have much field-experience with ORM in ColdFusion 9. But, that said, John really walks you through the app quite nicely, explaining all the details of how data gets flushed, how it gets stored, how it gets cached, and how the relationships work. I think you'd like this.

@Phillip,

Ha ha, probably :D

@Brian,

Awesome! I hope you enjoy it as much as I did.


Dec 19, 2011 at 7:43 PM // reply »
158 Comments

Ben,

Just re-installed CF9 at home and trying to learn Hibernate at work with Java.

Any updates in the past couple of months? I actually Googled "CF9 ORM Ben Nadel" hoping you'd have even more about it.

Checking out the Lulu link now.


Mar 6, 2012 at 12:39 PM // reply »
1 Comments

Ben,

I've been using CF for about 4 months and came across a problem using ORM that I haven't seen addressed anywhere else.

You seem to be one of the more knowledgeable CF developers and I've enjoyed reading and learning from your blogs.

I was hoping you could comment on the problem I'm having with ORM.

The problem is that hibernate is doing two inserts when I attempt to save a new entity. The first insert is successful, but the second errors because of duplicates.

My first question is why is it doing two inserts to start with (per the hibernate log)? The below code shows the uses of EntitySave after the EntityNew. The error occurs after the EntitySave and the message states:

Duplicate entry 'xxx' for key 'name'

Here is the code:

<cfset obj = EntityNew("#form.objname#")>
<cfset obj.setName("#form.name#")>
<cfset obj.setContact("#form.contact#")>
<cfset obj.setDescription("#form.description#")>
<cftry>
<cfset EntitySave(obj, "true")>
<cfcatch type="any" >
<cfif FindNoCase("duplicate", cfcatch.Message) GT 0>
<cfset errors["name"] = cfcatch.Message />
<cfelse>
<cfset errors["process"] = "There was an error processing 'EntitySave()' - errMsg: #cfcatch.detail#" />
</cfif>
</cfcatch>
</cftry>

Here is the log entry:

Hibernate:
insert
into
area
(activedate, isactive, inactivedate, name, description, leader)
values
(?, ?, ?, ?, ?, ?)
Hibernate:
insert
into
area
(activedate, isactive, inactivedate, name, description, leader)
values
(?, ?, ?, ?, ?, ?)
03/06 11:44:40 [web-6] HIBERNATE ERROR - Duplicate entry 'xxx' for key 'name'

03/06 11:44:40 [web-6] ERROR Duplicate entry 'xxx' for key 'name'

I bought John Whish's book on ORM and as far as I can tell I doing everything correctly.

Any advise or guidance you can provide will be greatly appreciated.

Thanks,

Scott


Mar 6, 2012 at 2:37 PM // reply »
11 Comments

@Scott, firstly welcome to CF - always nice to see a new developer :) I know you asked Ben, so I hope neither of you mind me hoping on the conversation.

It looks like you are assigning the key yourself, can you post your code for the 'area' entity? It's a bit hard to tell what is happening without seeing that.

Also, so you have event handling set up or anything in the onRequestStart / onRequestEnd that might cause odd behaviour?

BTW: you can save yourself some typing by not using the #'s when referencing variables like so:

<cfset obj = EntityNew(form.objname)>
<cfset obj.setName(form.name)>
<cfset obj.setContact(form.contact)>
<cfset obj.setDescription(form.description)>



Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 17, 2013 at 7:42 PM
HashKeyCopier - An AngularJS Utility Class For Merging Cached And Live Data
Ben - thanks so much for posting these Angular articles and findings, they've been a huge help towards learning one of the more 'complex' JavaScript frameworks out there (IMO). I have been using Angu ... read »
May 16, 2013 at 5:01 PM
UPDATE: Parsing CSV Data Files In ColdFusion With csvToArray()
Your code was the closest thing I've found to obtaining some direction for converting ISO fields to values that CF can translate properly. Thank you for posting! ... read »
May 15, 2013 at 10:37 PM
Very Simple Pusher And ColdFusion Powered Chat
hi id making plz easy ... read »
May 15, 2013 at 6:07 PM
Making SOAP Web Service Requests With ColdFusion And CFHTTP
Ben, you once again saved my bacon at work. Thank you, thank you, thank you! ... read »
May 15, 2013 at 4:15 PM
What If All User Interface (UI) Data Came In Reports?
@Josh, Thanks! @Ben, I definitely recommend the David West book "Object Thinking" I've been quoting from. It goes deeply into the philosophy and history of OO programming. His breadth ... read »
May 15, 2013 at 11:36 AM
Ask Ben: Print Part Of A Web Page With jQuery
I found this helpfull when you need to keep (refresh) the original parent page after closing the iframe child print dialog (Hoping you're not using a form at this time so it won't submit again): On ... read »
May 14, 2013 at 7:13 PM
What If All User Interface (UI) Data Came In Reports?
@Jonah, If there's any books you'd recommend on the subject of domain modelling, I'd love to hear it. I just downloaded the free PDF of "Domain Driven Design Quickly". Figured I'd give it ... read »
May 14, 2013 at 6:57 PM
The UX Of Prototyping: Low-Fidelity Is The New High-Fidelity
@Phillip, I'm not sure I follow what you mean? Are you saying that you looked at the list of widgets provided by the jQuery UI and let that be your style guide? ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools