Recently I have been working on a project using Groovy and Hibernate amongst other technologies and while I have definitely missed ColdFusion, it is good to get out of your comfort zone on occasion. The problem with using new technologies in a project setting is that most of your focus is on delivering the project and not on really learning the ins and outs of the technology. So, with a few minutes of breathing room allotted before the next project, I wanted to delve a bit deeper into Hibernate, especially with its integration into the next major release of ColdFusion.
To do this, my plan is to work through the book Java Persistence with Hibernate which was recommended to me and not only look at some of the capabilities behind Hibernate, but also see how Hibernates capabilities are presented within ColdFusion 9. This series should also serve as a bit of a review for the book and whether I would really recommend it for the ColdFusion development community. To answer one question before it comes up, my point here is not to say that Hibernate will solve the worlds problems and that every developer should use it. My goal is to simply take a closer look at Hibernate and the tools that we will have at our disposal with the next release of ColdFusion. It is up to you to decide if these capabilities are worth your time and effort to learn more about.
Now, on to the book. In going through some of the introduction and preface, I came across this definition of what Hibernate is:
Hibernate is an ambitious project that aims to be a complete solution to the problem of managing persistent data It mediates the applications interaction with a relational database, leaving the developer free to concentrate on the business problem at hand.
At first glance, this sounds great for a developer I get to focus on the application and its architecture while ignoring the whole concept of data persistence within the application. Reality is jumping up and down in the back of my head though saying this is too good to be true, so we will find out.
The first chapter of the book talks in general about persistence, how it fits into our software model and how it works in an object oriented paradigm. I know my very first web application dealt with storing and retrieving data from a little Microsoft Access database, so the concept of data persistence is nothing new to me and I assume it is not new to most developers. The chapter talks a bit about relational databases databases like Microsoft SQL Server or MySQL if you are not familiar with the term as well as briefly discussing SQL in terms of the language for writing queries and communicating with the database. While it is a well written intro, none of this should really be new for the average developer.
The twist with data persistence comes into play with what the books calls the paradigm mismatch. In other words, what happens when you start developing applications in an object oriented fashion and have to deal with persistence. With an object oriented application, you have abstract concepts like a Person and an Address. However, a relational database does not understand the concept of a Person or an Address. It understands a simple string like a first name or a street name for example. So, how do you go about saving and retrieving a Person instance to a relational database? While you can obviously introduce a data access layer to your application that handles this conversion( this is discussed in the persistence layers section ) , this is the problem that Hibernate is attempting to solve amongst others.
The sub-section entitled The Paradigm Mismatch is very good in explaining the different issues in mapping objects to a relational database including granularity, inheritance, polymorphism, and identities. The only thing here is that you have to have some knowledge of object oriented development and terminology, but I think that would be expected when reading a book on Hibernate which is all about persistence of object models.
I will cut this off here although I have only touched on half of the first chapter. The sections on persistence layers are equally as good and as such, I will leave something for you to read about yourself. I will look a bit more at the section that provides an overview of object/relational mapping (ORM) in the next post in this series.
Comments on: "A New Series: Hibernate & ColdFusion 9" (6)
I’d be interested in learning more about CF9’s Integration with Hibernate and LCDS. LCDS with Java and Hibernate supports updating hierarchical objects. I haven’t seen anything in the CF Docs about integrating CF9’s hibernate with LCDS for hierarchical data management.
Sounds interesting to me. I will add that to the topics I want to look into assuming I can get the time.
The Hibernate book link (to Safari Books Online) takes me to a different Java book. A search on Safari shows the link to the book you reference as http://my.safaribooksonline.com/9781932394887.
CF ORM does support persistence for hierarchical objects. Take a look at Inheritance mapping in CF9 docs for more details.
I can not think of any reason why CF would not work with LCDS for hierarchical object.
I’d be interested in how we can utilize more than one datasource or get around that one db mapping. We have at least 4 databases to connect in one app. Unless the only solution is cross db views.
@Dennis – Thanks, the link has been updated.