title: google cloudsql + google app engine + spring mvc + hierbnate/jpa error
body: <p>I have a problem with the cloudSQL and hibernates connections,I use spring mvc 3 with google app engine and also hibernate / JPA.
   here is the loggs in GAP console  :</p>
  
  <pre><code>Uncaught exception from servlet org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
  at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:427)
  at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
  at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
  at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
  at sun.proxy.$Proxy55.findAll(Unknown Source)
  at com.********************r.getCountryList(GeneralController.java:36)
  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:45)
  at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
  at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
  at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
  at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
  at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
  at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
  at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
  at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
  at org.mortbay.jetty.Server.handle(Server.java:326)
  at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
  at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
  at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
  at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:435)
  at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:442)
  at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:186)
  at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:306)
  at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:298)
  at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:439)
  at java.lang.Thread.run(Thread.java:722) Caused by: javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
  at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1361)
  at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289)
  at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1371)
  at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:60)
  at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:70)
  at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:59)
  at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:377)
  ... 47 more Caused by: org.hibernate.exception.JDBCConnectionException: Could not open connection
  at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:131)
  at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
  at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
  at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
  at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)
  at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
  at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
  at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
  at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1263)
  at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:57)
  ... 50 more Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:33)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
  at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
  at com.mysql.jdbc.MysqlIO.&lt;init&gt;(MysqlIO.java:344)
  at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2332)
  at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
  at com.mysql.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:792)
  at com.mysql.jdbc.JDBC4Connection.&lt;init&gt;(JDBC4Connection.java:47)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:33)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
  at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
  at co...(length 9240)
  </code></pre>
  
  <p>and here is my config file persistence.xml : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
      http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"&gt;
  
  &lt;persistence-unit name="*********" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;class&gt;com.******************&lt;/class&gt;
       &lt;class&gt;com.******************&lt;/class&gt;
      &lt;class&gt;com.******************&lt;/class&gt;
       &lt;class&gt;com.******************&lt;/class&gt;
  
      &lt;properties&gt;         
           &lt;property name="hibernate.connection.driver_class" value="com.google.appengine.api.rdbms.AppEngineDriver"/&gt;
           &lt;property name="hibernate.connection.url" value="jdbc:google:rdbms://instancename/tablename?zeroDateTimeBehavior=convertToNull"/&gt;
          &lt;property name="hibernate.connection.username" value="root"/&gt;
          &lt;property name="hibernate.connection.password" value=""/&gt;        
  
          &lt;property name="hibernate.connection.pool_size" value="0" /&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="update" /&gt; 
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>servlet-context.xml file : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:security="http://www.springframework.org/schema/security"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
      http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-3.1.xsd
      http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
       http://www.springframework.org/schema/security
       http://www.springframework.org/schema/security/spring-security-3.1.xsd"&gt;
  
  &lt;annotation-driven /&gt;
  
  &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  &lt;context:component-scan base-package="com.*********" /&gt;
  
  &lt;beans:bean
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
      &lt;beans:property name="suffix" value=".jsp" /&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="localeResolver"
      class="org.springframework.web.servlet.i18n.CookieLocaleResolver"&gt;
      &lt;beans:property name="cookieName" value="languageCookie"&gt;&lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  
  &lt;interceptors&gt;
      &lt;beans:bean id="localeChangeInterceptor"
          class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"&gt;
          &lt;beans:property name="paramName" value="language" /&gt;
      &lt;/beans:bean&gt;
  
  &lt;/interceptors&gt;
  
  &lt;beans:bean id="messageSource"
      class="org.springframework.context.support.ResourceBundleMessageSource"&gt;
      &lt;beans:property name="basename" value="messages" /&gt;
  &lt;/beans:bean&gt;
  
  &lt;jpa:repositories base-package="com.******************.repositories" /&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
  &lt;beans:bean id="hibernateExceptionTranslator"
      class="org.springframework.orm.hibernate4.HibernateExceptionTranslator"&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
    &lt;beans:property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /&gt;      
      &lt;beans:property name="jpaVendorAdapter"&gt;
  
          &lt;beans:bean
              class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
              &lt;beans:property name="showSql" value="true" /&gt;
              &lt;!--beans:property name="generateDdl" value="true" /--&gt;
              &lt;beans:property name="databasePlatform"
                  value="org.hibernate.dialect.MySQL5Dialect" /&gt;
  
  
          &lt;/beans:bean&gt;
      &lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  &lt;beans:bean id="transactionManager"
      class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;beans:property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;/beans:bean&gt;
  </code></pre>
  
  <p></p>