Database Timeout and Connection Pooling Overload
This Hibernate issue, "com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed," arises when a persistent connection is implicitly closed due to inactivity.
Cause:
The connection is established but remains inactive for an extended period, exceeding the server's "wait_timeout" or the client timeout settings like "connectionTimeout".
Resolution:
1. Adjust Server and Client Timeouts:
2. Configure Connection Pooling:
Sample hibernate.cfg.xml Configuration Using C3P0:
<code class="xml"><property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> <property name="c3p0.max_size">20</property> <property name="c3p0.min_size">5</property> <property name="c3p0.timeout">1800</property> <property name="c3p0.idleTestPeriod">3600</property> <property name="c3p0.maxIdleTime">3600</property></code>
Additional Tips:
The above is the detailed content of Why Am I Getting \'MySQLNonTransientConnectionException: No operations allowed after connection closed\' and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!