ClassCastException with "mvn gwt:run": GWT Maven Plugin + Hibernate

187 views
Skip to first unread message

Alexander Lochschmied

unread,
Nov 11, 2011, 5:29:34 AM11/11/11
to gwt-pl...@googlegroups.com
As indicated in my earlier post in this forum, I am having trouble with a ClassCastExeption when using
  • mvn gwt:run (GWT Maven plugin using Jetty)
  • JPA / Hibernate's EntityManager
The error is:

javax.persistence.PersistenceException: [PersistenceUnit: name] Unable to build EntityManagerFactory
...
Caused by: org.hibernate.HibernateException: Could not instantiate dialect class
...
Caused by: java.lang.ClassCastException: org.hibernate.dialect.MySQLDialect cannot be cast to org.hibernate.dialect.Dialect

...

(see full stack trace below)

When I do not specify hibernate.dialect in persistence.xml I get other ClassCastException. Deploying to Tomcat works fine.
This happens with GWT 2.3 (GWTP 0.6, GWT Maven Plugin 2.3.0-1) and GWT 2.4 (GWTP 0.7-SNAPSHOT, GWT Maven Plugin 2.4.0).

Maybe this comes from a dependency conflict?

<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-persist</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-assistedinject</artifactId>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
</dependency>
<dependency>
<groupId>com.google.gwt.inject</groupId>
<artifactId>gin</artifactId>
</dependency>
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-dispatch-client</artifactId>
</dependency>
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-dispatch-server</artifactId>
</dependency>
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-dispatch-server-guice</artifactId>
</dependency>
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-dispatch-shared</artifactId>
<version>${gwtp.version}</version>
</dependency>
<dependency>
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-processors</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
</dependency>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
</dependency>
</dependencies>


                00:00:04,265 [WARN] failed guiceFilter
javax.persistence.PersistenceException: [PersistenceUnit: name] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:916)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:887)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at com.google.inject.persist.jpa.JpaPersistService.start(JpaPersistService.java:94)
at com.google.inject.persist.PersistFilter.init(PersistFilter.java:77)
at com.google.inject.servlet.FilterDefinition.init(FilterDefinition.java:114)
at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:98)
at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:172)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:593)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:222)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
at com.google.gwt.dev.DevMode.main(DevMode.java:311)
Caused by: org.hibernate.HibernateException: Could not instantiate dialect class
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:82)
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:64)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:142)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:81)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:133)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2259)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2255)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:907)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:887)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at com.google.inject.persist.jpa.JpaPersistService.start(JpaPersistService.java:94)
at com.google.inject.persist.PersistFilter.init(PersistFilter.java:77)
at com.google.inject.servlet.FilterDefinition.init(FilterDefinition.java:114)
at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:98)
at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:172)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:593)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:222)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
at com.google.gwt.dev.DevMode.main(DevMode.java:311)
Caused by: java.lang.ClassCastException: org.hibernate.dialect.MySQLDialect cannot be cast to org.hibernate.dialect.Dialect
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:73)
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:64)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:142)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:81)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:133)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2259)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2255)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:907)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:887)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at com.google.inject.persist.jpa.JpaPersistService.start(JpaPersistService.java:94)
at com.google.inject.persist.PersistFilter.init(PersistFilter.java:77)
at com.google.inject.servlet.FilterDefinition.init(FilterDefinition.java:114)
at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:98)
at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:172)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:593)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:222)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
at com.google.gwt.dev.DevMode.main(DevMode.java:311)

Rob Ferguson

unread,
Nov 11, 2011, 6:30:17 PM11/11/11
to gwt-pl...@googlegroups.com
Hi,

I recently migrated an application from GWT 2.2, GWTP 0.5.1 to GWT 2.3 and GWTP 0.6 then GWT 2.4 and GWTP 0.6.

When I moved from GWT 2.2 to 2.3 I added:

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator</artifactId>  <!-- Required by GWT 2.3 for bean validation -->
    </dependency>

to the Hibernate dependencies:

    <!-- JPA/Hibernate dependencies -->
    <dependency>
      <groupId>org.hibernate.javax.persistence</groupId>
      <artifactId>hibernate-jpa-2.0-api</artifactId>

    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator</artifactId>  <!-- Required by GWT 2.3 for bean validation -->
    </dependency>

And the application works fine when run via mvn gwt:run and when deployed to Tomcat 7.

I'm not sure but the issue you are having may be related to JNDI look ups which don't work in hosted mode.

I have a hosted mode PU and a non-hosted mode PU configured via web.xml:

 <context-param>
    <param-name>PU-NAME</param-name>
    <param-value>HSQLDB-HOSTED-MODE-PU</param-value>
    <!-- <param-value>HSQLDB-TOMCAT7-CP-PU</param-value> -->
    <description>The name of the Persistence Unit used by the application.</description>
  </context-param>
  <context-param>
    <param-name>DS-NAME</param-name>
    <param-value>jdbc/HSQLDB-TOMCAT7-CP</param-value>
    <description>The name of the Data Source used by the application.</description>
  </context-param>

And persistence.xml:

  <!-- HSQLDB and TOMCAT7 -->
  <persistence-unit name="HSQLDB-TOMCAT7-CP-PU" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  <non-jta-data-source>java:comp/env/jdbc/HSQLDB-TOMCAT7-CP</non-jta-data-source>
    <class>com.gwtcx.server.domain.User</class>
    <class>com.gwtcx.server.domain.Account</class>
    <class>com.gwtcx.server.domain.Address</class>
    <class>com.gwtcx.server.domain.Report</class>
    <exclude-unlisted-classes/>
    <properties>
    <property name="javax.persistence.nonJtaDataSource" value="java:comp/env/jdbc/HSQLDB-TOMCAT7-CP" />
    <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
    </properties>
  </persistence-unit>

  <!-- HSQLDB HOSTED MODE PU -->
  <persistence-unit name="HSQLDB-HOSTED-MODE-PU" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.gwtcx.server.domain.User</class>
    <class>com.gwtcx.server.domain.Account</class>
    <class>com.gwtcx.server.domain.Address</class>
    <class>com.gwtcx.server.domain.Report</class>
    <exclude-unlisted-classes/>
    <properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
    <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
    <property name="hibernate.connection.url" value="jdbc:hsqldb:file:/tools/common/tomcat-7.0.16/webapps/serendipity/data/serendipitydb;ifexists=true" />
    <property name="hibernate.connection.username" value="sa" />
    <property name="hibernate.connection.password" value="" />
    </properties>
  </persistence-unit>

And context.xml:

  <!-- HSQLDB and TOMCAT7 CP -->
  <Resource name="jdbc/HSQLDB-TOMCAT7-CP"
            auth="Container"
            type="javax.sql.DataSource"
            factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
            driverClassName="org.hsqldb.jdbcDriver"
            username="sa" password=""
            testWhileIdle="true"
            testOnBorrow="true"
            testOnReturn="false"
            validationQuery="SELECT 1"
            validationInterval="30000"
            timeBetweenEvictionRunsMillis="30000"
            maxActive="100"
            minIdle="10"
            maxWait="10000"
            initialSize="10"
            removeAbandonedTimeout="60"
            removeAbandoned="true"
            logAbandoned="true"
            minEvictableIdleTimeMillis="30000"
            jmxEnabled="true"
            jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
            url="jdbc:hsqldb:file:/tools/common/tomcat-7.0.16/webapps/serendipity/data/serendipitydb;ifexists=true" />
            <!--  url="jdbc:hsqldb:file:/opt/tomcat/webapps/serendipity/data/serendipitydb;ifexists=true" /> -->
                     
And remember there is a /META-INF and a WEB-INF/classes/META-INF with copies of context.xml and persistence.xml.

Cheers
Rob

http://code.google.com/p/gwt-cx/


I am using GWT 2.4, GWTP 0.6

Alexander Lochschmied

unread,
Nov 14, 2011, 12:12:59 PM11/14/11
to gwt-pl...@googlegroups.com
Thanks Rob (and everybody) for trying to help! Unfortunately I had no luck yet and the ClassCastException is still there in jetty mode. I should have mentioned that it only happens in combination with "install" goal.

mvn install jetty:run

The ClassCastException is reported in console in tab "Jetty" before accessing any URL of the webapp.
BTW: I also don't understand why I can see my slf4j/log4j output only with "install" (and "gwt:run") goal.

Not sure if that worth mentioning, but without "install" on the other hand, there is a 404 error when accessing the problematic URL (see corresponding stacktrace below). Dispatcher is invoked and on server side (in the handler), a Hibernate based service is used (again, this works in Tomcat).

Currently it looks like I can only get rid of all exceptions in jetty by
  • using install: mvn install gwt:run
  • disabling the use of the service in the handler
  • disabling the two lines in DispatchServletModule to setup Hibernate:
//        logger.info("Setting up JPA");
//        install(new JpaPersistModule("name"));
//        logger.info("Starting JPA PersistFilter");
//        filter("/*").through(PersistFilter.class);

Regarding JNDI lookups, I don't thik we use it as we directly talk to DB using MySQL driver.
Any hints are greatly appreciated!

at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:209)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
at java.lang.Thread.run(Thread.java:662)

Rob Ferguson

unread,
Nov 14, 2011, 2:34:03 PM11/14/11
to gwt-pl...@googlegroups.com
When running in hosted mode do you place a copy of the JDBC driver for MySQL in WEB-INF/lib (the same file you place in tomcat\lib)?

e.g. for HSQLDB this would be hsqldb-2.0.01-rc1.jar

Alexander Lochschmied

unread,
Nov 15, 2011, 8:55:46 AM11/15/11
to gwt-pl...@googlegroups.com
Yes, mysql connector is in lib folder, see the "blue JAR" in list below.
Here is also my web.xml and the listener class:

<web-app>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.vishay.dsmgmt.graphing.server.guice.MyGuiceServletContextListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>Graphing.html</welcome-file>
</welcome-file-list>
</web-app>


public class MyGuiceServletContextListener extends GuiceServletContextListener {
    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new ServerModule(), new DispatchServletModule());
    }
}


public class DispatchServletModule extends ServletModule {
    static final Configuration cfg = Configuration.instance();
    static final Logger logger = Logger.getLogger(DispatchServletModule.class);

    @Override
    public void configureServlets() {
        install(new JpaPersistModule("dsmgmt"));
        filter("/*").through(PersistFilter.class);
        serve("/fileupload").with(DatasheetHtmlToPdf.class);
        serve("/filedownload").with(FileDownloadServlet.class);
        serve("/" + ActionImpl.DEFAULT_SERVICE_NAME + "*").with(DispatchServiceImpl.class);
    }
}

target/.../WEB-INF/lib:
    445.288 antlr-2.7.7.jar
    150.774 antlr-runtime-3.1.3.jar
      4.467 aopalliance-1.0.jar
     57.963 classmate-0.5.4.jar
    575.389 commons-collections-3.2.1.jar
     52.543 commons-exec-1.1.jar
     59.590 commons-fileupload-1.2.2.jar
    163.151 commons-io-2.1.jar
    284.220 commons-lang-2.6.jar
    313.898 dom4j-1.6.1.jar
    131.923 name-shared-0.1-SNAPSHOT.jar
  1.006.424 ehcache-core-2.4.3.jar
    710.492 guice-3.0.jar
     36.998 guice-assistedinject-3.0.jar
     27.633 guice-persist-3.0.jar
     65.012 guice-servlet-3.0.jar
  5.004.997 gwt-servlet-2.3.0.jar
     28.339 gwtp-dispatch-server-0.6.jar
     17.184 gwtp-dispatch-server-guice-0.6.jar
     30.402 gwtp-dispatch-shared-0.6.jar
     81.426 hibernate-commons-annotations-4.0.0.Final.jar
  4.347.499 hibernate-core-4.0.0.CR6.jar
    127.259 hibernate-ehcache-4.0.0.CR6.jar
    471.832 hibernate-entitymanager-4.0.0.CR6.jar
    102.661 hibernate-jpa-2.0-api-1.0.1.Final.jar
     70.928 jandex-1.0.3.Final.jar
    644.148 javassist-3.12.1.GA.jar
      2.497 javax.inject-1.jar
     60.542 jboss-logging-3.1.0.CR1.jar
     11.209 jboss-transaction-api_1.1_spec-1.0.0.Final.jar
    859.016 jna-3.2.3.jar
    213.781 jsch-0.1.44-1.jar
    281.579 jsoup-1.6.1.jar
    481.535 log4j-1.2.16.jar
    789.885 mysql-connector-java-5.1.18.jar
  1.351.561 org.eclipse.jgit-1.0.0.201106090707-r.jar
    601.287 pd4ml-3.80b1.jar
    149.846 pd4ml-ss-css-3.80b1.jar
     25.962 slf4j-api-1.6.4.jar
      9.748 slf4j-log4j12-1.6.4.jar
    743.673 sqljet-1.0.4.jar
    172.023 stringtemplate-3.2.jar
  1.889.196 svnkit-1.3.5.jar
    251.371 trilead-ssh2-build213-svnkit-1.3-patch.jar
     47.433 validation-api-1.0.0.GA.jar
    109.318 xml-apis-1.0.b2.jar


Alexander Lochschmied

unread,
Nov 15, 2011, 10:44:24 AM11/15/11
to gwt-pl...@googlegroups.com
Update: As we need a solution soon, I tried to avoid the guice portion as a last resort.

The (bad?) idea: Skipping the two "red" lines in listener class (see earlier post) and instead creating BaseDao class similar to yours Rob, which creates an EntityManagerFactory once:

public abstract class BaseDao {
    protected static String puName = "name";
    private static boolean initialised = false;
    private static EntityManagerFactory emf = null;
    public static EntityManager createEntityManager() {
        if (! initialised) {
            emf = Persistence.createEntityManagerFactory(puName);
            initialised = true;
        }
        return emf.createEntityManager();
    }
}

Even now I get the ClassCastException with "mvn gwt:run":

[INFO] javax.persistence.PersistenceException: [PersistenceUnit: name] Unable to build EntityManagerFactory
[INFO] at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
[INFO] at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
[INFO] at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
[INFO] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
[INFO] at com.vishay.dsmgmt.shared.server.BaseDao.createEntityManager(BaseDao.java:36)
[INFO] at com.vishay.dsmgmt.shared.server.images.ImageMetaDataService.findImageMetaData(ImageMetaDataService.java:56)
[INFO] at com.vishay.dsmgmt.graphing.server.GetGraphFilesActionHandler.<init>(GetGraphFilesActionHandler.java:60)
[INFO] at com.vishay.dsmgmt.graphing.server.GetGraphFilesActionHandler$$FastClassByGuice$$33220583.newInstance(<generated>)
[INFO] at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)
[INFO] at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:60)
[INFO] at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
[INFO] at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
[INFO] at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:978)
[INFO] at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
[INFO] at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:974)
[INFO] at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)
[INFO] at com.gwtplatform.dispatch.server.guice.actionhandlervalidator.LazyActionHandlerValidatorRegistryImpl.createInstance(LazyActionHandlerValidatorRegistryImpl.java:141)
[INFO] at com.gwtplatform.dispatch.server.guice.actionhandlervalidator.LazyActionHandlerValidatorRegistryImpl.findActionHandlerValidator(LazyActionHandlerValidatorRegistryImpl.java:80)
[INFO] at com.gwtplatform.dispatch.server.AbstractDispatchImpl.findHandler(AbstractDispatchImpl.java:196)
[INFO] at com.gwtplatform.dispatch.server.AbstractDispatchImpl.doExecute(AbstractDispatchImpl.java:147)
[INFO] at com.gwtplatform.dispatch.server.AbstractDispatchImpl.execute(AbstractDispatchImpl.java:111)
[INFO] at com.gwtplatform.dispatch.server.AbstractDispatchServiceImpl.execute(AbstractDispatchServiceImpl.java:80)
[INFO] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[INFO] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[INFO] at java.lang.reflect.Method.invoke(Method.java:597)
[INFO] at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
[INFO] at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
[INFO] at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
[INFO] at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
[INFO] at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
[INFO] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
[INFO] at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:263)
[INFO] at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:178)
[INFO] at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
[INFO] at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:62)
[INFO] at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118)
[INFO] at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
[INFO] at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
[INFO] at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
[INFO] at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
[INFO] at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
[INFO] at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
[INFO] at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
[INFO] at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
[INFO] at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
[INFO] at org.mortbay.jetty.Server.handle(Server.java:324)
[INFO] at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
[INFO] at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
[INFO] at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
[INFO] at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
[INFO] at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
[INFO] at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
[INFO] at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
[INFO] Caused by: org.hibernate.HibernateException: Could not instantiate dialect class
[INFO] at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:82)
[INFO] at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:64)
[INFO] at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:142)
[INFO] at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
[INFO] at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:165)
[INFO] at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:139)
[INFO] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
[INFO] at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2259)
[INFO] at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2255)
[INFO] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
[INFO] at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76)
[INFO] at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
[INFO] ... 54 more
[INFO] Caused by: java.lang.ClassCastException: org.hibernate.dialect.MySQLDialect cannot be cast to org.hibernate.dialect.Dialect
[INFO] at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:73)
[INFO] ... 65 more

Rob Ferguson

unread,
Nov 15, 2011, 4:28:10 PM11/15/11
to gwt-pl...@googlegroups.com
Hi,

-> Caused by: java.lang.ClassCastException: org.hibernate.dialect.
MySQLDialect cannot be cast to org.hibernate.dialect.Dialect
[INFO] at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:73)

In your persistence.xml is the dialect set correctly? e.g. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

Also there is no hibernate-validator-4.1.0.Final.jar in your list (as per my previous post):

    <dependency>
      <groupId>org.hibernate</groupId>

      <artifactId>hibernate-validator</artifactId>  <!-- Required by GWT 2.3 for bean validation -->
    </dependency>

And you have a couple of JBoss libs?  Are you setting transaction-type="RESOURCE_LOCAL" or "JTA"?

Cheers
Rob

Lee Fisher

unread,
Nov 15, 2011, 4:39:04 PM11/15/11
to gwt-pl...@googlegroups.com
Hi Rob,
I'm also working with Alexander on this.
Thanks for your help.

The dialect is set as you mention.  Actually when I remove the dialect completely, I still see it find dialect in the console but the error becomes:
org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory cannot be cast to org.hibernate.engine.transaction.api.TransactionFactory

Transaction type is RESOURCE_LOCAL.

It seems to work when deployed in tomcat.  Also when I do jetty:run, the hibernate parts appear to work from the console (the app doesn't because not everything is configured).  It is only happening in gwt:run, which seems pretty strange, but there must be some incorrect reference or jar.
Thanks,
Lee

Rob Ferguson

unread,
Nov 15, 2011, 5:24:08 PM11/15/11
to gwt-pl...@googlegroups.com
HI,

What version of the gwt maven plugin are you using?

    <gwt-maven-plugin.version>2.4.0</gwt-maven-plugin.version>

Cheers
Rob

Lee Fisher

unread,
Nov 15, 2011, 5:25:49 PM11/15/11
to gwt-pl...@googlegroups.com
Hi Rob,
        <gwt.version>2.3.0</gwt.version>
        <gwt-maven-plugin.version>2.3.0-1</gwt-maven-plugin.version>
        <gwtp.version>0.6</gwtp.version>

Regards,
Lee

Rob Ferguson

unread,
Nov 15, 2011, 5:33:20 PM11/15/11
to gwt-pl...@googlegroups.com
HI,

As far as I can recall the only time I received a class cast exception was when I left out the Hibernate validation dependency.

Can you try adding it in?

And then try:

mvn gwt:clean
mvn clean
mvn install
mvn gwt:run

Cheers
Rob

Alexander Lochschmied

unread,
Nov 16, 2011, 5:25:11 AM11/16/11
to gwt-pl...@googlegroups.com
Hi Rob, unfortunately no luck (below the list of JARs in webapp).
Regards,
Alexander


      445.288 antlr-2.7.7.jar
      150.774 antlr-runtime-3.1.3.jar
        4.467 aopalliance-1.0.jar
       57.963 classmate-0.5.4.jar
      575.389 commons-collections-3.2.1.jar
       52.543 commons-exec-1.1.jar
       59.590 commons-fileupload-1.2.2.jar
      163.151 commons-io-2.1.jar
      284.220 commons-lang-2.6.jar
      313.898 dom4j-1.6.1.jar
      131.953 dsmgmt-shared-0.1-SNAPSHOT.jar
    1.006.424 ehcache-core-2.4.3.jar
      710.492 guice-3.0.jar
       36.998 guice-assistedinject-3.0.jar
       27.633 guice-persist-3.0.jar
       65.012 guice-servlet-3.0.jar
    5.004.997 gwt-servlet-2.3.0.jar
       28.339 gwtp-dispatch-server-0.6.jar
       17.184 gwtp-dispatch-server-guice-0.6.jar
       30.402 gwtp-dispatch-shared-0.6.jar
       81.426 hibernate-commons-annotations-4.0.0.Final.jar
    4.347.499 hibernate-core-4.0.0.CR6.jar
      127.259 hibernate-ehcache-4.0.0.CR6.jar
      471.832 hibernate-entitymanager-4.0.0.CR6.jar
      102.661 hibernate-jpa-2.0-api-1.0.1.Final.jar
      366.592 hibernate-validator-4.2.0.Final.jar

Rob Ferguson

unread,
Nov 16, 2011, 2:15:30 PM11/16/11
to gwt-pl...@googlegroups.com
And you still get the same exception?

Can you post the full stack trace.

Alexander Lochschmied

unread,
Nov 16, 2011, 2:41:14 PM11/16/11
to gwt-pl...@googlegroups.com
At least the three "Caused bys" did not change (and probably all details remained the same too) yes. So it's (most likely) still the same stacktrace from original post (see also below). If you want, I can double check tomorrow.

I've also posted a "short" summary in other forums that describes what happens when dialect is not set for example:

One thing I didn't mention yet: The class cast exception occurs when hosted mode is started before any page is accessed (which gives HTTP error). It does not get thrown if those two lines are removed

        install(new JpaPersistModule("PUname"));

        filter("/*").through(PersistFilter.class);

But if you surround them with try catch, the error cannot be caught and logged in Eclipse console; instead it's again reported in console in Jetty tab only. In other words: It's reported only in Jetty console, never in "normal" console (stdout).

Thanks for your patience!
Alexander
javax.persistence.PersistenceException: [PersistenceUnit: name] Unable to build EntityManagerFactory
Caused by: org.hibernate.HibernateException: Could not instantiate dialect class
	at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:82)
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:64)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:142)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:81)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:133)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2259)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2255)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
	at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76)
Caused by: java.lang.ClassCastException: org.hibernate.dialect.MySQLDialect cannot be cast to org.hibernate.dialect.Dialect
	at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:73)
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:64)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:142)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:81)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:133)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2259)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2255)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
	at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76)

Alexander Lochschmied

unread,
Nov 21, 2011, 9:00:06 AM11/21/11
to gwt-pl...@googlegroups.com
Thanks Rob for your support, you were right, it had to with validation jars.

Finally it seems to work with downgraded Hibernate (3.6.3) and additional dependencies:
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<!--version>1.0.0.GA</version-->
<version>${javax-validation.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<!--version>1.0.0.GA</version-->
<version>${javax-validation.version}</version>
<classifier>sources</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<!--version>1.0.0.Final</version-->
<version>${hibernate-jpa.version}</version>
</dependency>
<!-- jsr 303 (javax.validation) provider-->
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-core</artifactId>
<!--version>0.3-incubating</version-->
<version>${bval.version}</version>
</dependency>
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr303</artifactId>
<!--version>0.3-incubating</version-->
<version>${bval.version}</version>
</dependency>
This is based on a hint by Juan in the GWT forum.
Reply all
Reply to author
Forward
0 new messages