ColdFusion 9 debugging hibernate schema exports

Word Count: 124

I have really been diving deep into the new ColdFusion 9 hibernate integration and I love it. I was working with a many-to-many relationship last night and I was having some issues. To enable hibernate there is 1 setting that is required and a few for this example that we are going to use for this example.

Back in my application I have a product entity and a category entity. The product can be associated with multiple categories and categories can obviously have multiple products. This would allow us to get all the categories a product is a part of as well us list any products that belong to a category. A many-to-may relationship is setup in the database using a link table that holds a foreign key to each record. Below is my product entity as it was and my category entity as it was.

I am not going to get into all the details of setting up a many-to-many relationship because thats not the focus on this post. Now that I thought I was all ready to go I reloaded my application hoping my 3 new tables would be written (Product/Category/ProductCategory). When I ran the application I got the following error.

Error during DDL export
Well I am no hibernate expert but after asking a few people and doing some reading I realized this was an issue with the schema export. Basically something was not right with the way I setup my relationship here so the resulting schema was incorrect. How do you debug something like this is what I asked myself? I asked a friend and he said you need to enable ddl debugging in the hibernate settings file. I run my server right from ColdFusion Builder so I am already seeing a bunch of errors in the console view but I am not seeing what I need.

If you go to the cf_root\lib\log4j.properties file we can make a quick change so that we can see some debugging information. You should be able to find the following line:

### log schema export/update ### #log4j.logger.org.hibernate.tool.hbm2ddl=ERROR
What we want to do is log more just errors, we want to get some debugging information back, so change ERROR to DEBUG. Next I reloaded my application again and got some more information back.
Column 'Category.categoryId' is not the same data type as referencing column 'ProductCategory.categoryId' in foreign key 'FKD05546ED5424A3B7'.
I checked the database and sure enough my categoryId field was getting created as a varchar in the Category table and a integer in the ProductCategory table. I went back to my category entity and realized that I didn't set its type to numeric. I reloaded the application and everything worked out just how I wanted it to.

The new hibernate integration is simply awesome. It is so easy to use yet powerful enough for us to get under the hood in situations like this one. If I were you I would start your local servers within ColdFusion Builder (or a console) so you can start to see the different things going on behind the scenes. It really gives you some insight on to how things are working, and how they are not!

Comments

#1 Posted By: Kerr Posted On: 12/4/09 9:25 AM
Thanks for posting this, I had a similar issue and the log4j setting change allowed me to quickly locate the issue. I am a bit miffed that Adobe didn't go to greater lengths to integrate ORM logging into the well established CF logging interfaces. People are unfortunately having to spend a lot of time figuring out the issues behind the scenes.

This is funny - your example has a many-to-many relationship, which in some MVC frameworks is referred to as HABTM (has and belongs to many). The captcha text for my post here is "habt" -- no m I know, but still funny.
#2 Posted By: Dan Vega Posted On: 12/4/09 10:29 AM |
Author Comment
The thing is you really can't do anything to make this easier. This is low level configuration that requires a restart. You don't want this turned on by default because it's only used in a development environment and I am sure would cause some performance issues in production. Glad It helped you out!

* My captcha is pretty smart :)


Post Your Comment

Leave this field empty







Show Captcha

If you subscribe, any new posts to this thread will be sent to your email address.

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.