title: MySQL connection and hibernate c3p0 settings, timeout after 8 hours?
body: <p>I am using Amazon EC2 to run my Java Wicket app and I have Amazon MySQL instance running for the application. All works fine, but after 8 hours my database connection is lost. I have tried to configure c3p0 settings so that this would not happen. I have also tried to update MySQL settings, but no help.</p>
  
  <p>Here is my persitence.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;persistence xmlns="xyz"&gt;
  &lt;persistence-unit name="mysqldb-ds" transaction-type="RESOURCE_LOCAL"&gt;
  
    &lt;description&gt;Persistence Unit&lt;/description&gt;
    &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
  
    &lt;properties&gt;
      &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
      &lt;property name="hibernate.show_sql" value="true"/&gt;
      &lt;property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/&gt;
      &lt;property name="hibernate.connection.username" value="XXXXX"/&gt;
      &lt;property name="hibernate.connection.password" value="YYYYY"/&gt;
      &lt;property name="hibernate.connection.url" value="jdbc:mysql://xxxx.yyyyy.us-east-1.rds.amazonaws.com:3306/paaluttaja"/&gt;
      &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/&gt;
      &lt;property name="connection.pool_size" value="1" /&gt;
      &lt;property name="cache.provider_class" value="org.hibernate.cache.NoCacheProvider" /&gt;
      &lt;property name="hibernate.c3p0.min_size" value="5" /&gt;
      &lt;property name="hibernate.c3p0.max_size" value="20" /&gt;
      &lt;property name="hibernate.c3p0.timeout" value="300" /&gt;
      &lt;property name="hibernate.c3p0.max_statements" value="50" /&gt;
      &lt;property name="hibernate.c3p0.idle_test_period" value="3000" /&gt;
    &lt;/properties&gt;
  
  &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>I am making queries like this:</p>
  
  <pre><code>@Service
  public class LoginServiceImpl implements LoginService{
  
  @Override
  public Customer login(String username, String password) throws LSGeneralException {
      EntityManager em = EntityManagerUtil.getEm();
  
      TypedQuery&lt;Customer&gt; query = em.createQuery("SELECT c FROM Customer c "
              + "WHERE c.username = '" + username + "' "
              + "AND c.password = '" + password + "'", Customer.class);
  
      Customer customer = null;
  
      try {
          customer = (Customer) query.getSingleResult();
      }catch(Exception e){
          if(e instanceof NoResultException){
              throw new LSGeneralException("login.failed.wrong.credentials", e);
          }else{
              throw new LSGeneralException("failure", e);
          }
      }
  
      customer.setLogged(true);
  
      return customer;
  
  }
  
  }
  </code></pre>
  
  <p>All help would be appreciated.</p>