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.

2 Responses to “Glassfish to Tomcat w/ JDBC Connection Pooling”

  1. Eric Holsinger Says:

    Try adding it as a jdbc resource in glassfish, with a jdbc conneciton pool.

  2. Anonymous Says:

    you did the pizza erd sloppily
    instead of having dancing or dead crow you had crazy crow.
    just sayin…
    useful information on the site though.


© 2012 Mike Desjardins. All Rights Reserved.