Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to avoid MySQL connection timeout errors with EclipseLink?
    text
    copied!<p>MySQL closes a connection after a certain time if nothing happens (<a href="http://dev.mysql.com/doc/refman/5.1/en/gone-away.html" rel="nofollow">8 hours by default</a>). The time can be influenced by the wait_timeout variable in the configuration.</p> <p>I have an Eclipse RCP application where I use EclipseLink as persistence framework and I get an error when the client exceeds the timeout:</p> <pre><code> Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ... at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.Util.getInstance(Util.java:386) ... com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException ... org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor... </code></pre> <p>I tried to set autoReconnect/autoReconnectForPools=true but this does not help. </p> <p>Thanks</p> <p><strong>EDIT</strong></p> <p>In my persistence.xml I have the following properties set:</p> <pre><code> &lt;property name="eclipselink.jdbc.read-connections.max" value="10" /&gt; &lt;property name="eclipselink.jdbc.cache-statements" value="true" /&gt; &lt;property name="eclipselink.jdbc.read-connections.shared" value="true" /&gt; </code></pre> <p>The rest of the configuration is done in the code:</p> <pre><code> Map&lt;Object, Object&gt; map = ... map.put(PersistenceUnitProperties.JDBC_URL,...); map.put(PersistenceUnitProperties.JDBC_USER,...); map.put(PersistenceUnitProperties.JDBC_PASSWORD, ...); map.put(PersistenceUnitProperties.JDBC_DRIVER, ...); map.put(PersistenceUnitProperties.CLASSLOADER, this.getClass() .getClassLoader()); map.put(PersistenceUnitProperties.TARGET_DATABASE, "MySQL"); entityManagerFactory = new PersistenceProvider() .createEntityManagerFactory("...", map); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload