Can't configure MySQL datasource in GWT + Hibernate + MySQL project

gwt, hibernate

Solution

I had to completely change my answer after having played with your project code. Here's a new one:

You happened to take a Jetty Launcher code from earlier versions of GWT (I believe). Once I replaced your `CustomJettyLauncher` with the the version that I had (modified as per the same recommendations but on top of a version from the GWT 2.4 codebase) it all came together. Proper initialization of initial context, the `java:comp/env`, etc.

You can actually make your version work with the 6.1.11 too if you add the `java:comp/env` into the name in `jetty-env.xml` but I don't think going that route makes sense. I couldn't make it work with 6.1.26 and it doesn't really matter since using proper Jetty Launcher codebase makes it work with either version.

Here's the launcher code that works (package and class name is just how you had it so it's a "drop-in" replacement): https://gist.github.com/2854726

Leaving a trail for someone who might stumble upon this post later. You get Jetty to show its `DEBUG` logs in GWT hosted (dev) mode by launching GWT with `SPAM` log level.

Problem

I'm attempting to migrate a JSP / Hibernate project to GWT / Hibernate. Briefly, the issue appears to be that the MysqlConnectionPoolDataSource class from jetty-env.xml is evidently not getting instantiated, causing the resource reference from web.xml to fail. Our Hibernate setup works fine in non-GWT projects. I'm using Eclipse Indigo, Google Suite Plugin 2.5, Google GWT Designer 2.4.2. Here are the steps I took and excerpts of files that I think matter. (Apologies in advance - this is a little bit verbose but wanted to be sure my question is complete and clear.) My war/WEB-INF/classes/hibernate.cfg.xml includes: ``` <property name="hibernate.connection.datasource"> java:comp/env/jdbc/nndb </property> ``` The web.xml includes: ``` <resource-ref> <description>NN Database Connection Pooling</description> <res-ref-name>jdbc/nndb</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> ``` I also created CustomJettyLauncher as described here and added Eclipse run config to use it (Run Config Arguments -server com....CustomJettyLauncher) This results in: jetty-6.1.x [WARN] Configuration problem at NN Database Connection Poolingjdbc/nndbjavax.sql.DataSourceContainerShareable java.lang.IllegalStateException: Nothing to bind for name javax.sql.DataSource/default Presumably at this point I need an entry in the jetty-env.xml defining the resource: ``` <?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure class="org.mortbay.jetty.webapp.WebAppContext"> <New id="nndb" class="org.mortbay.jetty.plus.naming.Resource">     <Arg>jdbc/nndb</Arg>     <Arg> <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">            <Set name="Url">jdbc:mysql://dbserver/dbname</Set>            <Set name="User">dbuser</Set>            <Set name="Password">dbpasswd</Set>     </New>     </Arg>    </New> </Configure> ``` But the above error (Nothing to bind for name javax.sql.DataSource/default) remains. Interestingly, if I intentionally bugger up the datasource classname in jetty-env.xml (e.g. NOSUCH.com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource) there's no gripe, so it may not even be trying to instantiate that class. (Similar "tracer" errors for WebAppContext and Resource DO produce gripes, so it's only ConnectionPoolDataSource that it's not trying to instantiate.) Whew! Does anyone see what's wrong? Any recommendations would be greatly appreciated. Thanks in advance!

Original source

Related problems