I have a persistence unit that worked on Apache TomEE 7.0.4(eclipselink 2.6.4), but after upgrade to TomEE 7.1.0(eclipselink 2.7.4), JPA calls failed after some time. The persistence.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="xxxPU" transaction-type="JTA">
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<jta-data-source>xxxDB</jta-data-source>
<properties>
<property name="openjpa.jdbc.DBDictionary" value="mysql"/>
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
</properties>
</persistence-unit>
</persistence>
The datasource defined in tomee.xml is
<Resource id="xxxDB" type="javax.sql.DataSource">
UserName = xxxx
Password = yyyy
JdbcDriver = com.mysql.jdbc.Driver
JdbcUrl = jdbc:mysql://localhost/dbname
JtaManaged = true
factory = org.apache.tomcat.jdbc.pool.DataSourceFactory
ConnectionProperties = autoReconnect=true;autoReconnectForPools=true;zeroDateTimeBehavior=convertToNull;useUnicode=yes;characterEncoding=UTF-8;useSSL=false
defaultAutoCommit = false
testOnBorrow = true
validationQuery = SELECT 1
validationInterval = 30000
</Resource>
The failure happens after sometime with the log here:
15-May-2019 19:12:49.236 SEVERE [ajp-nio-8009-exec-10] org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException EjbTransactionUtil.handleSystemException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
Error Code: 0
Apparently the mysql connection is closed, but actually is not. I have a servlet that when HTTP GET, proves the datasource is OK:
@Resource(name=xxxDB)
DataSource dataSource;
....
try (Connection connection = dataSource.getConnection()) {
// do a query to prove connection OK
}
I have cron job that GET this servlet every hour. Connection is OK even after JPA throws com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException
My environment Java 8, TomEE 7.1.0, Eclipselink 2.7.3