I've built a simple application using JPA for persistence. It's hosted in Tomcat, so I'm managing the EntityManagers myself.
Everything seems to work fine, but every morning when I browse to my app, I see...
java.sql.SQLException: ORA-02396: exceeded maximum idle time, please connect again
vendor/version
---------------------------------------
tomcat/5.5
toplink-essentials/2.0-58
Has anyone seen anything like this?
P.S. The JpaServiceUtil class is a utility class used by my services. Also, the Ant-style placeholders ${} in the persistence.xml get replaced via a Maven filter.
<persistence xmlns="
http://java.sun.com/xml/ns/persistence"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" version="1.0"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="JPAPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<mapping-file>META-INF/nativequeries.xml</mapping-file>
<class>com.path.to.my.Object</class>
<properties>
<property name="toplink.logging.level" value="OFF"/><!-- OFF FINE -->
<property name="toplink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/> <!-- update to match database-->
<property name="toplink.jdbc.url" value="${jdbc.url}"/> <!-- update to match database-->
<property name="toplink.jdbc.password" value="${jdbc.password}"/> <!-- update to match database-->
<property name="toplink.jdbc.user" value="${jdbc.user}"/> <!-- update to match database-->
<property name="toplink.jdbc.read-connections.max" value="20"/>
<property name="toplink.jdbc.read-connections.min" value="5"/>
<property name="toplink.jdbc.timeout" value="100"/>
</properties>
</persistence-unit>
</persistence>
final class JpaServiceUtil{
private static final EntityManagerFactory factory = Persistence
.createEntityManagerFactory("JPAPersistenceUnit");
/**
*
*/
static <T>List<T> findAllByNamedQuery(Class<T> clazz, String name,
Object... params){
return findAllByNamedQuery(clazz, 0, -1, name, params);
}
/**
*
*/
static <T>List<T> findAllByNamedQuery(Class<T> clazz, int startPosition, int max, String name,
Object... params){
EntityManager em = null;
try{
em = PersistenceManager.getEntityManager();
Query query = loadNamedQuery(em, name, params);
if(max > -1){
query.setFirstResult(startPosition).setMaxResults(max);
}
return query.getResultList();
}finally{
try{em.close();}catch(Throwable e){e.printStackTrace();}
}
}
...
}
public class VariantService{
/**
*
* @return
*/
public List<Variant> findAllInvalid(){
return JpaServiceUtil.findAllByNamedQuery(Variant.class,
"Variant.findAllInvalid");
}
}
[Message sent by forum member 'smmcneill' (smmcneill)]
http://forums.java.net/jive/thread.jspa?messageID=245101