Using Hibernate with ColdFusion, part 5
This is last part of article describing prototype solution for using Hibernate with CFML. In this part we will configure ColdFsuion server and deploy test application connected to MSSQL 2005 data base.
Previous parts are here: part 1, part 2, part 3, part 4.
We start by downloading Hibernate from hibernate.org web site. Version we need is Hibernate Core. When writing this article latest version was 3.2.6 GA. When Hibernate is downloaded we have to copy hibernate3.jar file from Hibernate distribution to directory {CFUSION_INSTALL_DIR}/hibernate. We also need some dependencies - for minimal installation we need following jar files from lib directory:
- antlr-2.7.6
- commons-collections-2.1.1
- commons-logging-1.0.4
- dom4j-1.6.1
- xml-apis
Now go to ColdFusion Administrator, Java and JVM page and add following line to ColdFusion class path:
{CFUSION_INSTALL_DIR}/hibernate
Replace {CFUSION_INSTALL_DIR} with the directory where your CF is installed. Now build HiberCFClassLoader project and export it as JAR to the same directory where Hibernate jar files are located. If everything went fine you should be able to execute this line of code without any errors:
<cfset cfg = createObject("java", "org.hibernate.cfg.Configuration").init() />
We can now drop HiberCF to our test site. Create following directory /uk/co/riait/hibercf under web root and place contents of HiberCF.zip in it. Change hibercf.application_root in hibercf.properties so it matches your web root (for example c:/inetpub/wwwroot.hibercf/).
Create directory /uk/co/riait/hibercftest and place contents of HiberCFTest.zip in it. This archive contains:
- User.cfc
- User.hbm.xml
- test.cfm
- HiberCFTest.bak
Go to your SQL Server Management Studio and restore HiberCFTest.bak data base as HiberCFTest. There is only one table called Users. It has one default row which will be used for first test. When data base is restored go to ColdFusion Administrator and create data source for the application (called HiberCFTest).
You can now try running test file. You will see following error thrown by ColdFusion:
uk.co.riait.hibercftest.User
The error occurred in C:\{your_root}\uk\co\riait\hibercf\JavaBuilder.cfc: line 89
...
This error appears because JavaBuilder.cfc outputs Java source to the directory of CFC file. The same directory is used to place class files. Compiled Java class has exactly the same package as CFC. But ColdFusion doesn’t know that package yet so HiberCFClassLoader is not able to load required class. To fix the problem go to ColdFusion Administrator, Java and JVM page and append path from hibercf.application_root to ColdFusion class path, restart CF server service.
When you refresh test.cfm it will print user name on the screen. Test file contains full add, update, delete process. To test execute commented code.
As this application is only prototype it is not quite well understood how data types such as integers, longs, decimals, bits should be handled. My tests are showing that in most cases these data types may be declared as strings for Hibernate. It may differ for data bases other than MSSQL but as long as appropriate types of generators are set everything should work fine with strings.
Is it working for you? Comments are open for all parts of this article.
About this entry
You’re currently reading “ Using Hibernate with ColdFusion, part 5 ,” an entry on ria:it
- Published:
- 6:50 pm on 25/05/2008
- Category:
- ColdFusion, Hibernate
1 Comment
Jump to comment form | comments rss [?] | trackback uri [?]