Glassfish to Tomcat w/ JDBC Connection Pooling
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:
<property name="connection.datasource">java:/comp/env/jdbc/ApptrackDB</property>
Glassfish doesn’t like that. Once I changed it to:
<property name="connection.datasource">jdbc/ApptrackDB</property>
Everything worked swimmingly.
Tags: glassfish, hibernate, java, programming
This entry was posted on Monday, January 21st, 2008 at 2:31 pm and is filed under blog. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.