GWT + Hibernate + MySQL inside Eclipse

538 views
Skip to first unread message

Bill Compton

unread,
May 20, 2012, 7:42:49 PM5/20/12
to google-we...@googlegroups.com
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.

The short-short version is that the MysqlConnectionPoolDataSource class from jetty-env.xml is evidently not getting instantiated, causing the resource reference from web.xml to fail.

Here are the steps I took and excerpts of files that I think matter. (Apologies in advance - this is a 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>

A service class AuthenticateServiceImpl.authenticate(Credentials c) calls DAOFactory.getDefaultInstance().getCustomerDAO();
The above works fine in my pure tomcat (non-GWT project). But in the GWT project it fails with:
    SEVERE: Could not find datasource: java:comp/env/jdbc/nndb
    javax.naming.NameNotFoundException; remaining name 'jdbc/nndb'
So, I added following entry to web.xml:
    <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>
and 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 <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>
java.lang.IllegalStateException: Nothing to bind for name javax.sql.DataSource/default

Presumably at this point I need an entry in either the jetty-env.xml or jetty-web.xml file (which?) defining the resource. I tried jetty-env.xml:
<?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 (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.)

I also tried using a jetty-web.xml file but that is evidently not getting read at all.

Whew!

Does anyone see what's wrong? Any recommendations would be greatly appreciated.

Thanks in advance!

Bill Compton

unread,
Jun 1, 2012, 7:49:13 PM6/1/12
to google-we...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages