Here’s your don’t-waste-hours-on-something-silly-that-I-did tip for the day.
I recently had the opportunity to change an existing in-house web application from running under Tomcat 5.5, to Glassfish v2. The application uses JDBC connection pooling in the application server, and uses JNDI to find the pool. The only stumbling block I encountered was that, immediately after deploying the application, Hibernate would always complain that it couldn’t find the connection:
org.hibernate.HibernateException: Could not find datasource at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56) at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124) at . . (yadda yadda) . Caused by: javax.naming.NameNotFoundException: No object bound to name java:/comp/env/jdbc/MyDB . .
As it turns out, the datasource that I was using in hibernate.cfg.xml was perfectly fine for Tomcat, but not for Glassfish. I had put the fully qualified JNDI file in my config file:
Glassfish doesn’t like that. Once I changed it to:
Everything worked swimmingly.