Sunday, October 21, 2007

Case Sensitivity in MySQL

So I have this application that I am writing that uses Struts 1.x and Hibernate with a MySQL back end. I am doing the actual development with Netbeans on Windows XP but the production server is a Linux machine running Redhat Enterprise 4. For a while everything went well in that I could deploy from the Windows machine onto the Linux environment and see no ill effects. Recently I ran head first into a brick wall with this arrangement.

I made some changes to my database schema and attempted to upload the application. While running the tests on the Linux environment I started getting some strange data related errors.

After fiddling around for several hours I realized that MySQL is case sensitive in the Linux environment but not in the Windows environment. Generally, I use all lower case names in the database schema so I never noticed before.

I carelessly (but probably luckily) used an uppercase name in the change that i made to the schema. Then using mysqldump to export the database on the Windows machine and re-import the database on the Linux server caused a unforeseen effect. Mysqldump lowercased all the identifiers in my schema. So Foo became foo.

I have no idea how the import did not complain...but Hibernate used my uppercase identifiers when generating the SQL statements and blam...all hell breaks loose.

I went through all my configurations for Hibernate to ensure that I did not make the mistake anywhere else, then re-created the database schema and re-deployed. Now everything works. I wonder what other surprises are in store for me for being so bold (read:stupid) as to work in a mixed environment.

Friday, October 05, 2007

Hibernate InstantiationException

Sometimes our own carelessness is our downfall. I have an application where I am using Hibernate to handle persistence. I have been working on this application for about a year now and have grown quite fond of Hibernate.

I have an inheritance hierarchy with an abstract class called Case and two concrete sub classes named MedstarCase and RoadsideCase. I am using the table per subclass strategy for persisting these objects. This worked fine until suddenly this morning, code that worked all along blew up.

I got org.hibernate.InstantiationException
Cannot instantiate abstract class or interface:! I immediately revisited my mappings and painstakingly ran tests to determine the cause. But I found nothing to give me any clues. So I paused to think. What did I do this morning to my code.

I added a new collection to the Case. But the Case already had several collections and none of them caused problems before...and I checked that the mappings were similar.

I had re-imported some data into the database. Aha! I turned to the database to check my data. I had cleared the entire database and re-imported data to run some tests on the data migration code that I would need this coming weekend. I counted the number of rows in the Case table and the number of rows in the medstarcase and roadsidecase tables and found1367 Cases but only 600 medstar cases.

All along I was trying to instantiate Cases that did not correspond to any concrete class. Needless to say this was carelessness on my part for not verifying my data. I keep learning these valuable lessons the hard way though.

After clearing the data, fixing the data import program and re-importing the data, everything worked fine.

Thursday, October 04, 2007

Development Environments

Its been more than a year since I last posted anything here. A lot has happened in that time but hopefully I will be able to post more often now. Today I want to comment a bit on editor features.

For the last year and a half I have been using Netbeans as my IDE of choice. It took some time but I was finally converted from eclipse. Now don't get me wrong, eclipse is a very good development environment and probably enjoys wider support than Netbeans. So nothing is wrong with it. There is one place where Netbeans has the advantage though...installation and configuration.

With Netbeans, the installation is easy and the add ons are just as easy. Finding the updates and installing them are a very simple process. Setting up eclipse and configuring all the tools that you need to work with has been a headache. After the set up everything goes smoothly and the tools do a great job. In my case I found that I have to set up several different machines and after a while I started appreciating the simplicity of the Netbeans installation.

I see that with Netbeans 6.0 all the common tools are included in the installation so its now even easier than before. I would usually download Netbeans and the Visual Web Pack and several others. I am looking forward to using 6.0 for this reason.