title: Strange and rare DB related exception
body: <p>A few days before I got a very strange exception that someone couldn't log in to my application. Now I'm to reproduce it...</p>
  
  <p>Here is the exception:</p>
  
  <pre><code>org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.TransactionException: JDBC begin transaction failed:
      at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:428)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:372)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:417)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:255)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
      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.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:92)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
      at com.sun.proxy.$Proxy82....
      ....at java.lang.Thread.run(Thread.java:724)
  Caused by: javax.persistence.PersistenceException: org.hibernate.TransactionException: JDBC begin transaction failed:
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1377)
      at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
      at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1387)
      at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:62)
      at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:71)
      at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:378) ... 87 more
  Caused by: org.hibernate.TransactionException: JDBC begin transaction failed:
      at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:76)
      at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
      at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1392)
      at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:59) ... 89 more
  Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 32,971,422 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
      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:526)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
      at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121)
      at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3670)
      at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3559)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4110)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
      at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2809)
      at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:5333)
      at com.mchange.v2.c3p0.impl.NewProxyConnection.setAutoCommit(NewProxyConnection.java:912)
      at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:72) ... 92 more
  Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
      at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3119)
      at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3570) ... 100 more
  </code></pre>
  
  <p>I got only once so far, and have no idea how to reproduce. Another thousands of log in were successfully. If I'm not mistaken, the root cause is a kind of timeout on database side - I don't know what, just an intuition... Therefore extended the report with the last request time and the time when the server generates the report, but nothing has happened since.  </p>
  
  <p>Any suggestion what is it or how to reproduce?</p>