I’ve been writing an application that uses Hibernate as a persistence layer instead of just writing SQL statements myself. Hibernate itself has been a complete success. The query language is easy to pick up if you already know SQL, and it really does save a lot of labor. As part of that process, I decided to move my database configuration from a property file based system that I’d come up with myself to JNDI. If you don’t know, JNDI is a system that enables applications to retrieve information of various kinds from something called a “JNDI context.” Most application servers and servlet containers have a JNDI provider built in so that you can store environment-specific information there, making it easy to move your applications from your local machine, to the staging server, to production.

The application is to be deployed under Tomcat, but I was developing it under Resin. There’s an added wrinkle in that my staging server runs Tomcat 4.1.18 under Linux and the production server is to be Tomcat 4.0.x that’s built into a reasonably well known J2EE application server. So I figured out how to set up the JNDI stuff for configuring data sources under Resin. I got that working after much fussing around, and so my next step was to make sure it would work under Tomcat. Well, getting it to work under Tomcat was a ton of work. I had to add the JNDI stuff to the server.xml file, then I had to add aliases to it in context configuration files, then I had to add the Oracle driver to Tomcat’s class path. I’m leaving out some of the other hacking I did. Finally, I got it working. Feeling good about getting the JDBC stuff to work, I tried configuring the SMTP server via JNDI. That worked under Tomcat but then wouldn’t work under Resin.

After wasting way, way too much time on those problems, I built more features for the application and decided to move it to staging to show to some end users. When I went home today, I still didn’t have it working. My context configuration files were preventing my app from being deployed for some reason, and I had the same class path issues as before. Even if I get that to work, I’ll still have problems when I deploy it to the bastardized version of Tomcat where it’s supposed to ultimately live.

I think I’m going to back to my older, more primitive system for configuring these sorts of things. JNDI seems great, but I’m still waiting for the killer implementation. Resin seems closer to Tomcat, but even it wasn’t painless.