Book Review: ColdFusion ORM
August 08, 2013
Book Review: "ColdFusion ORM: A guide to developing applications using ColdFusion ORM" by John Whish
I've had this in the "to read" pile for a couple of months now (virtually anyway -- I read the PDF version). I was familiar with the concepts of what Hibernate does, and have looked at the beginning pieces of ColdFusion ORM previously, but haven't needed to use it on a project until now. To be fair, I still don't -need- to use ORM on a project, but learning it now coincided nicely with an app I'm working on (2, actually), so here we are.
Overall the book is great. If you're not familiar with ORM, haven't used it (or variations -- Hibernate, Transfer, etc), this is a great first look at the benefits to ORM and why you might want to consider it for your next project.
There are some minor inconsistencies in grammatical style and bits like fonts/punctuation that I'm sure will be cleaned up with the next revision of the book (and none of it was major enough to take value awy from the information being presented).
Also, I'm not a huge fan of the book being written in first-person tense. It makes the content (to me) feel somewhat less professional grade, and more like a series of blog entries, rather than a book I paid money for. This is obviously me being very nit-picky, and again it didn't really take away from the actual training material the book had to offer.
The book starts off with introductory samples, showing the code and quick screen captures or CFDump outputs of what should be expected. Each topic basically builds on the previous one, and it follows the same format through most of the book: describe the problem briefly, show some sample code, show sample output, and move on to the next point.
In the forward of the book, there are several mentions of Adobe ColdFusion, after that the content seems pretty platform agnostic (aside from a couple references to CFIDE and the like). There's no mention of Railo in the book but that probably has to do more with red tape and less to do with compatibility with the code. I haven't typed in all the samples personally, but I don't see why they couldn't all run on Railo 4. (A few other third party tools were mentioned in the book -- Validate This and HyRule, among others.)
As it got into the intermediate/advanced features of ORM, I started to have more questions than earlier in the book. It also seemed like the content got thinner as the book went on. The intro/beginner code samples were great. There were some topics further on that were only discussed briefly; I would have liked more details.
For example...there is mention of the ability to switch between caching engines, but there's no mention of why/when I might need to do this. Referencing a real-world problem would have been nice here.
Other highlights / notes I made while reading the book (some of which pertain to ORM itself and not the book specifically) --
* More advanced tricks for the real world please. For instance, has anyone found an easy way to include the genreated SQL into the CF Debugging page output? (Not -everyone- is using CF Builder, and if you're on shared hosting, you can't access the server logs either.) I know, the most vocal among the CF community these days disagree with me on this point. However I deal with a lot of different clients, and CF Builder is no more used than DreamWeaver or CF Eclipse among the teams I talk to.
* The "DiscriminatorColumn/DiscriminatorValue" thing seems like a total hack to me. Is this really the way Hibernate works under the hood (at the Java level)? Does Railo's implementation do the same thing?
* Before reading, I thought the "ormtype" attribute was for referencing the database-specific data type (int, bigint, etc). Now I've learned that's not the case, and that the "sqltype" attribute is for mapping to the specific database type. Though now it makes me wonder...why do we even have the 'ormtype' field at all? I suppose if I need my app to work on Oracle and MySQL and SQL Server that's useful. Is there another (more common) use case that I'm just not seeing?
* The entire "data types and precision" chapter should have been much earlier in the book, in my opinion. There's a little flipping back/forth between talking about OO concepts, and database concepts. I was approaching this book with more of a database mindset: I wanted to see how I can use ORM to write less SQL, while not having to muck with my database structure too much (if at all). All of the questions I had early on pertained to this sort of data; had this chapter been presented earlier, I think it would have helped me see exactly how/what Hibernate is doing for me, and how it relates (no pun intended) to my code and database.
* The "notnull" attribute is poorly named. Again, I don't know off hand if this is the way Hibernate does it, or if it's an Adobe specific thing. But naming a variable "is NOT something" is backwards and unintuitive. "isNullable" would be my preference.
* More details on when to use the length/nullable parameters would have been nice (e.g. sqltype, unique, uniquekey). The book started off with great samples and use cases, but in this section, we only have 1 or 2-sentence descriptions of each attribute. It'd be nice to know if there's a real world situation where I'd need to start using these options. Earlier in the book we have notes about when certain situations will cause an exception, or how to work around bugs in ColdFusion 9, but nothing like that is noted in this chapter.
* Tips and Tricks at the end was great! Now that the book has covered a pretty extensive set of the functionality in ORM, it's nice to see some of the shortcuts and other "real world" uses for ORM. Reading this section was raising my interest level in ORM again (the previous chapter or two were for features that I don't see myself needing any time soon).
* "Entities with the same name"...it notes I can do this "by passing in the value specified in the entityname attribute", however it doesn't know to -what- I'm passing that value. I assume the EntityLoad() or EntityNew() functions, but the extra line of code would have made this example less ambiguous.
* The Hibernate Statistics tip was great!
* I -love- that none of the Hibernate / ORM functionality discussed in the book made the assumption that "everyone is on CF Builder" (a big pet peeve of mine). (I've been to many presentations where the title is "Topic X", but the actual content ended up being "Topic X, But ONLY If You Use Toolset Y"...which can be very frustrating for part of the audience.)
* The Constructor Arguments gotcha was helpful. I would have liked a codesample/screenshot here.
* Detached Entities was another "gotcha" I'm glad to be aware of! However I wanted more content in here too. For example...the book never discusses WHY the code has become a detatched entity. Is it merely because I stored my Author object in the Session scope as opposed to the Variables scope? Are there ANY scopes I can store persistent objects in and have them still work? This could be made clearer to the reader. The main solution given in that chapter was to just store the Author ID and reload the rest of the Author data on every page request. This might be fine for some apps but could be a performance concern elsewhere. I feel like this chapter could be expanded more and include some "cookbook" style examples.
* "Generated Has Methods and Non-Persisted Entities" -- more info please! The very last paragraph in this section was info I'd been waiting through 177 pages for. I have several apps that use GUIDs as their primary keys; thus far all the examples assumed I was using auto-incremented integers, with no mention of how to change that. This could be expanded into its own section, and moved up about 140 pages earlier in the book. :)
* I find it interesting how much detail was given for "Setting Up An Apache Derby Database", but several assumptions were made about the readers knowledge of object-oriented programming, specifically Interfaces. (FYI, I don't use Apache Derby databases for anything.) Why not just point people to any number of web pages that discuss Apache Derby instead?
"ColdFusion ORM" is definitely worth picking up and reading, and at 180-ish pages it won't take you very long.
After reading the whole thing, I wonder if an 'ORM cookbook' might be in order. That'd leave this as a good-sized quality intro to ORM. Then for people wanting more, they can pick up the cookbook and and look at some of the advanced features in more detail than were presented here.
-nolan
I've had this in the "to read" pile for a couple of months now (virtually anyway -- I read the PDF version). I was familiar with the concepts of what Hibernate does, and have looked at the beginning pieces of ColdFusion ORM previously, but haven't needed to use it on a project until now. To be fair, I still don't -need- to use ORM on a project, but learning it now coincided nicely with an app I'm working on (2, actually), so here we are.
Overall the book is great. If you're not familiar with ORM, haven't used it (or variations -- Hibernate, Transfer, etc), this is a great first look at the benefits to ORM and why you might want to consider it for your next project.
There are some minor inconsistencies in grammatical style and bits like fonts/punctuation that I'm sure will be cleaned up with the next revision of the book (and none of it was major enough to take value awy from the information being presented).
Also, I'm not a huge fan of the book being written in first-person tense. It makes the content (to me) feel somewhat less professional grade, and more like a series of blog entries, rather than a book I paid money for. This is obviously me being very nit-picky, and again it didn't really take away from the actual training material the book had to offer.
The book starts off with introductory samples, showing the code and quick screen captures or CFDump outputs of what should be expected. Each topic basically builds on the previous one, and it follows the same format through most of the book: describe the problem briefly, show some sample code, show sample output, and move on to the next point.
In the forward of the book, there are several mentions of Adobe ColdFusion, after that the content seems pretty platform agnostic (aside from a couple references to CFIDE and the like). There's no mention of Railo in the book but that probably has to do more with red tape and less to do with compatibility with the code. I haven't typed in all the samples personally, but I don't see why they couldn't all run on Railo 4. (A few other third party tools were mentioned in the book -- Validate This and HyRule, among others.)
As it got into the intermediate/advanced features of ORM, I started to have more questions than earlier in the book. It also seemed like the content got thinner as the book went on. The intro/beginner code samples were great. There were some topics further on that were only discussed briefly; I would have liked more details.
For example...there is mention of the ability to switch between caching engines, but there's no mention of why/when I might need to do this. Referencing a real-world problem would have been nice here.
Other highlights / notes I made while reading the book (some of which pertain to ORM itself and not the book specifically) --
* More advanced tricks for the real world please. For instance, has anyone found an easy way to include the genreated SQL into the CF Debugging page output? (Not -everyone- is using CF Builder, and if you're on shared hosting, you can't access the server logs either.) I know, the most vocal among the CF community these days disagree with me on this point. However I deal with a lot of different clients, and CF Builder is no more used than DreamWeaver or CF Eclipse among the teams I talk to.
* The "DiscriminatorColumn/DiscriminatorValue" thing seems like a total hack to me. Is this really the way Hibernate works under the hood (at the Java level)? Does Railo's implementation do the same thing?
* Before reading, I thought the "ormtype" attribute was for referencing the database-specific data type (int, bigint, etc). Now I've learned that's not the case, and that the "sqltype" attribute is for mapping to the specific database type. Though now it makes me wonder...why do we even have the 'ormtype' field at all? I suppose if I need my app to work on Oracle and MySQL and SQL Server that's useful. Is there another (more common) use case that I'm just not seeing?
* The entire "data types and precision" chapter should have been much earlier in the book, in my opinion. There's a little flipping back/forth between talking about OO concepts, and database concepts. I was approaching this book with more of a database mindset: I wanted to see how I can use ORM to write less SQL, while not having to muck with my database structure too much (if at all). All of the questions I had early on pertained to this sort of data; had this chapter been presented earlier, I think it would have helped me see exactly how/what Hibernate is doing for me, and how it relates (no pun intended) to my code and database.
* The "notnull" attribute is poorly named. Again, I don't know off hand if this is the way Hibernate does it, or if it's an Adobe specific thing. But naming a variable "is NOT something" is backwards and unintuitive. "isNullable" would be my preference.
* More details on when to use the length/nullable parameters would have been nice (e.g. sqltype, unique, uniquekey). The book started off with great samples and use cases, but in this section, we only have 1 or 2-sentence descriptions of each attribute. It'd be nice to know if there's a real world situation where I'd need to start using these options. Earlier in the book we have notes about when certain situations will cause an exception, or how to work around bugs in ColdFusion 9, but nothing like that is noted in this chapter.
* Tips and Tricks at the end was great! Now that the book has covered a pretty extensive set of the functionality in ORM, it's nice to see some of the shortcuts and other "real world" uses for ORM. Reading this section was raising my interest level in ORM again (the previous chapter or two were for features that I don't see myself needing any time soon).
* "Entities with the same name"...it notes I can do this "by passing in the value specified in the entityname attribute", however it doesn't know to -what- I'm passing that value. I assume the EntityLoad() or EntityNew() functions, but the extra line of code would have made this example less ambiguous.
* The Hibernate Statistics tip was great!
* I -love- that none of the Hibernate / ORM functionality discussed in the book made the assumption that "everyone is on CF Builder" (a big pet peeve of mine). (I've been to many presentations where the title is "Topic X", but the actual content ended up being "Topic X, But ONLY If You Use Toolset Y"...which can be very frustrating for part of the audience.)
* The Constructor Arguments gotcha was helpful. I would have liked a codesample/screenshot here.
* Detached Entities was another "gotcha" I'm glad to be aware of! However I wanted more content in here too. For example...the book never discusses WHY the code has become a detatched entity. Is it merely because I stored my Author object in the Session scope as opposed to the Variables scope? Are there ANY scopes I can store persistent objects in and have them still work? This could be made clearer to the reader. The main solution given in that chapter was to just store the Author ID and reload the rest of the Author data on every page request. This might be fine for some apps but could be a performance concern elsewhere. I feel like this chapter could be expanded more and include some "cookbook" style examples.
* "Generated Has Methods and Non-Persisted Entities" -- more info please! The very last paragraph in this section was info I'd been waiting through 177 pages for. I have several apps that use GUIDs as their primary keys; thus far all the examples assumed I was using auto-incremented integers, with no mention of how to change that. This could be expanded into its own section, and moved up about 140 pages earlier in the book. :)
* I find it interesting how much detail was given for "Setting Up An Apache Derby Database", but several assumptions were made about the readers knowledge of object-oriented programming, specifically Interfaces. (FYI, I don't use Apache Derby databases for anything.) Why not just point people to any number of web pages that discuss Apache Derby instead?
"ColdFusion ORM" is definitely worth picking up and reading, and at 180-ish pages it won't take you very long.
After reading the whole thing, I wonder if an 'ORM cookbook' might be in order. That'd leave this as a good-sized quality intro to ORM. Then for people wanting more, they can pick up the cookbook and and look at some of the advanced features in more detail than were presented here.
-nolan