I am using JPA 2.0 with EclipseLink, Glassfish, and NetBeans. I am experiencing issues with connection timeouts after extended periods of inactivity. I've looked pretty hard for ways to either:
(1) Check for JPA's connection and then re-establish its connection if disconnected
(2) Keep the JPA's connection active as much as possible
However, I can't really find a solution for either. The closest thing I can find is this post: How To modify Eclipselink JPA 2.0 connection retry behavior .
If there is someway to directly work with the JPA's connection, it'd be nice but it's buried within the library.
What you state you are looking for is usually provided by the datasource, in this case it would be configurable in Glassfish as described here:
https://blogs.oracle.com/JagadishPrasath/entry/connection_validation_in_glassfish_jdbc
If you want to do this without a datasource, for instance by passing a URL to the provider and have it handle connections, it will be EclipseLink specific. EclipseLink does have options that can be configured when it attempts to reconnect and retry queries, such as the
public void setPingSQL(String pingSQL)
public void setQueryRetryAttemptCount(int queryRetryAttemptCount)
public void setDelayBetweenConnectionAttempts(int delayBetweenConnectionAttempts)
methods that can be set on the DatabaseLogin or DatabasePlatform classes through a customizer.