title: amazon aws ubuntu java mysql webservice "Error calling Driver#connect"
body: <p>we have some web services running on tomcat 7 / java7 / hibernate / mysql5.
  Everything is running perfectly on localhost tomcat server on my pc but when we deploy the application on the AWS Ubuntu server, we get this error message:</p>
  
  <blockquote>
    <blockquote>
      <p>Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl
      configure WARN: HHH000402: Using Hibernate built-in connection pool
      (not for production use!) Mar 25, 2014 9:59:52 PM
      org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl
      buildCreator INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at
      URL
      [jdbc:mysql://ec2-54-197-214-209.compute-1.amazonaws.com:3306/ChronoMetriq]
      Mar 25, 2014 9:59:52 PM
      org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl
      buildCreator INFO: HHH000046: Connection properties: {user=root,
      password=<strong>**} Mar 25, 2014 9:59:52 PM
      org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl
      buildCreator INFO: HHH000006: Autocommit mode: false Mar 25, 2014
      9:59:52 PM
      org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl
      configure INFO: HHH000115: Hibernate connection pool size: 10 (min=1)
      Error Creating SessionFactory: **Error calling Driver#connect</strong> null Mar
      25, 2014 9:59:52 PM com.sun.jersey.spi.container.ContainerResponse
      mapMappableContainerException SEVERE: The RuntimeException could not
      be mapped to a response, re-throwing to the HTTP container
      <strong>java.lang.NullPointerException</strong>
              at ca.chronometriq.webterm.restapi.Process.getQueueName(Process.java:132)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:606)
              at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
              at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
              at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
              at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
              at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
              at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
              at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
              at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
              at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
              at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
              at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
              at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
              at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
              at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
              at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
              at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
              at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1024)
              at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
              at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
              at java.lang.Thread.run(Thread.java:744)</p>
    </blockquote>
  </blockquote>
  
  <p>Here is my hibernate.cfg.xml file content:</p>
  
  <pre><code>    &lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" &gt;
  &lt;hibernate-configuration&gt;
       &lt;session-factory&gt;
  
          &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://myaddress.compute-1.amazonaws.com:3306/ChronoMetriq&lt;/property&gt;
          &lt;property name="hibernate.connection.release_mode"&gt;auto&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;********&lt;/property&gt;
          &lt;property name="hibernate.connection.pool_size"&gt;10&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQL5InnoDBDialect&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
          &lt;mapping class="ca.chronometriq.webterm.model.Clinic" /&gt;
          ...
  
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>And here is our session factory code:</p>
  
  <pre><code>public class DataObjectFactory {
      @SuppressWarnings({ "rawtypes" })
      private static final ThreadLocal threadLocal = new ThreadLocal();
  
      private static ServiceRegistry serviceRegistry;
      private static SessionFactory sessionFactory;
  
      private static Configuration configuration;
  
  
      private static final Logger logger = Logger.getLogger(DataAccessInterface.class.getName());
  
  
      static {
          try {
              configuration = new Configuration().addResource("hibernate.cfg.xml");
              configuration.configure();
  
              serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
              sessionFactory = configuration.buildSessionFactory(serviceRegistry);
  
  
          } catch (Exception e) {
              System.err.println("Failed to create sessionFactory object." + e);
          }
      }
  
      private DataObjectFactory(){
      }
  
      @SuppressWarnings("unchecked")
      public static Session getSession() throws HibernateException {
  
          Session session = (Session) threadLocal.get();
  
          if (session == null || !session.isOpen()) {
              if (sessionFactory == null) {
                  rebuildSessionFactory();
              }
              session = (sessionFactory != null) ? sessionFactory.openSession() : null;
  
              threadLocal.set(session);
          }
          return session;
      }
  
  public static void rebuildSessionFactory() {
      try {
          configuration = new Configuration().addResource("hibernate.cfg.xml");
          configuration.configure();
  
          serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
          sessionFactory = configuration.buildSessionFactory(serviceRegistry);
  
      } catch (HibernateException e) {
          System.err.println("Error Creating SessionFactory: " + e.getMessage());
      }
  }
  
  @SuppressWarnings("unchecked")
  public static void closeSession() throws HibernateException {
      Session session = (Session) threadLocal.get();
      threadLocal.set(null);
      if (session != null) {
          session.flush();
          session.close();
      }
  }
  
  public static SessionFactory getSessionFactory() {
      configuration = new Configuration().addResource("hibernate.cfg.xml");
      configuration.configure();
  
      serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
      sessionFactory = configuration.buildSessionFactory(serviceRegistry);
  
      return sessionFactory;
  }
  
  public static Configuration getConfiguration() {
      return configuration;
  }
  
  
      public static void closeRegistry() throws Exception{
          if(serviceRegistry!= null) {
              StandardServiceRegistryBuilder.destroy(serviceRegistry);
          }
      }
  }
  </code></pre>
  
  <p>Any idea why this happens?</p>