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 Hibernate’s 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 world’s 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 application’s 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.