Hibernate and Coldfusion 7 Success

08Aug07

It’s about time that I actually wrote something on this blog, and why not hopefully make it something that people out there can use in some form or another. This post is mostly about what it takes to get Coldfusion and Hibernate to work nicely together.

Some background first; The company that i work is working on a project that required a faily sophisticated domain model that required extensive object interaction, as well as most of our developers being most comfortable with java. The object interaction and the desire to use Hibernate for persistance pushed us down the road of using Java for the domain model and use CF for the presentation tier.
I do know about the CF ORM’s but for various reasons we chose not to go that direction.

From what i’ve read around the web, it’s fairly common knowledge that getting Hibernate to work on anything other than CF8 is a royal pain in the proverbial, mainly due to the incompatibility between a few jar files that Hibernate uses and similar versions. The prime offenders are commons-logging and log4j both from the Apache project.

Before I start i have to give credit to Kurt Bonnet who gave this whole idea some viability.
The Orginal Idea
In the comments of matt Woodward’s blog there was a comment from Kurt who posted such a great idea about getting Hibernate working properly, and that was to take advantage of the open source nature of all the required projects and create a custom build of hibernate, commons-logging, and log4j so that there would be no conflict in the package namespaces between what is required by hibernate and what ColdFusion has preloaded.

Step 1

Download Source code packages for the following
– Hibernate 3.2
– Apache commons-logging 1.0.4
– log4j 1.2.11

Each of the above sources are included in the binary downloads, except maybe commons-logging. log4j and commons-logging jar files were pre included with hibernate, so thats why i chose that particular version. There is no particular reason for using these particular versions of the files, it should work for newer versions.

Step 2

i) Refactor the Log4j Package

Use any of your favourite refactoring tools to change the namespace/package name from org.apache.log4j to be cf.org.apache.log4j.

- Build the package using the ant script. Resolving dependencies of the ant script is the biggest issue, but i’ll leave that part as an exercise for the reader.
The most important step with all of the refactoring is to make sure that ALL of the occurrances of the package names are changed. The main thing that is fairly easy to miss is the package name in strings of the Factories. I missed this initially in the log4j package, and it caused all sorts of issues when the logs were being instanciated by commons-logging.

ii) Refactor the Commons Logging Package
– from org.apache.commons.logging
– to cf.org.apache.commons.logging

– Change any reference to log4j from org.apache.log4j to cf.org.apache.log4j

Rebuild it using the ant script.

iii) Refactor Hibernate

Wherever Hibernate references org.apache.commons.logging change it to refer to the newly built package of cf.org.apache.commons.logging.

Make sure you also change references in strings as well. The main thing that is easy to miss is the ANTLR .g files that are built when the ANT script is used.These .g files are antlr grammars that contain references to the commons-logging package. If you dont use the ant script, the antlr tasks wont get run and hibernate will have all sorts of issues when it tries to initialise itself.

I’ll provide downloads a bit later on…. maybe, if i can get the time

About these ads


No Responses Yet to “Hibernate and Coldfusion 7 Success”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: