Sunday, September 27, 2015

Deploy issue of GWT with Hibernate

Hello, everyone:

i am playing with GWT(2.6) with Hibernate recently. the integration works well in devmode, i can operate local mysql db correctly. But when i tried to deploy the war to my local tomcat server, i got following error:

27-Sep-2015 16:48:45.335 SEVERE [http-apr-8080-exec-9] org.apache.catalina.core.ApplicationContext.log Exception while dispatching incoming RPC call Service method 'public abstract com.meta.myapp.shared.ResponseDataBox com.meta.myapp.client.rpc.MyappService.remoteCall(com.meta.myapp.shared.RequestDataBox)' threw an unexpected exception: java.lang.NullPointerException
at javax.servlet.http.HttpServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.tomcat.websocket.server.WsFilter.doFilter(
at Source)
Caused by: java.lang.NullPointerException
at com.meta.myapp.server.HibernateUtil.getSessionFactory(
at com.meta.myapp.server.SchedulerServiceServlet.remoteCall(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
... 26 more

Here was how my HibernateUtil implemented, mostly following the guide on
It looks like the static segment was not invoked at all.
public class HibernateUtil {
        private static final SessionFactory sessionFactory;   
        private static Configuration config;
        static {
            try {   
                config = new Configuration();
                // addMapping(config);
                // Create the SessionFactory from hibernate.cfg.xml   
                sessionFactory = config.configure().buildSessionFactory();  

            } catch (Throwable ex) {   
                System.err.println("Initial SessionFactory creation failed.\n" + ex);   
                throw new ExceptionInInitializerError(ex);   
        public static SessionFactory getSessionFactory() {   
            return sessionFactory;   

Here was my server.xml of tomcat 8.0:
      <Host name="localhost"  appBase="c:/yshaoxp/workspace/Myapp"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
<Context path="" reloadable="true" docBase="war" debug="1"/>


and, here is my hibernate.cfg.xml:

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/myapp</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>

<property name="show_sql">true</property>
<property name="">update</property>
<!-- Enable Hibernate's automatic session context management -->
                <property name="current_session_context_class">thread</property>

                <!-- Disable the second-level cache -->
                <property name="cache.use_second_level_cache">false</property>

It works well when i work on devmode with eclipse. Your support is appreciated!

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment