ColdFusion Mappings and Hibernate

Here’s a quick tip on an issue that set me back a couple of hours. ORM stands for Object/Relational Mapping, an object-based method of reducing the amount of code required to communicate with a database. Hibernate is an ORM Framework included in ColdFusion 9.

I’m new to ORM so I started out by creating a simple project with all components contained under the same application. It was a small struggle to get past the new terminology and occasional mistakes and/or omissions in the online documentation, but a few hours and several expletives later, I was up and running.

My next step was to apply the method to an existing site. The major difference being that I wanted my ORM object definitions to be inaccessible externally. This required creating a ColdFusion mapping, which I created using the CF Administrator.

I set everything up and ran a test page which replied with an error: “Hibernate mapping for … component not found.”

After several hours of Googling, combined with a lot of trial and error, I discovered that in order to use Hibernate with a CF mapping, the mapping must application level. Once I deleted my mapping from CF Admin and added it to my Application.CFC, the error stopped and my results appeared.

One other note to keep in mind when configuring your ColdFusion application to use Hibernate: ORM settings must go in Application.CFC instead of the old-school Application.cfm.