eclipselink
eclipselink copied to clipboard
eclipselink.jdbc.timeout set on the EntityManager is Ignored & problems with javax.persistence.query.timeout
Reference: https://github.com/payara/Payara/issues/4895
1. Issue:
It seems that eclipse link is ignoring javax.persistence.query.timeout
as long as eclipselink.query.timeout.unit
isn't set, basically the same issue as described here: https://www.ibm.com/support/pages/apar/PI53372
2. Issue
Setting the values directly on the Entity Manager:
@PersistenceContext EntityManager em;
em.setProperty("javax.persistence.query.timeout", 10);
em.setProperty("eclipselink.query.timeout.unit", "MILLISECONDS"); // added for eclipse link support
em.setProperty("eclipselink.jdbc.timeout", "1"); // shouldn't be needed just to make sure we have set all values we can set
Seems not to be possible -- like with Hibernate -- or as defined in the JPA Spec. The odd thing about that is, that the values can be read on the EntityManager. Means if they are set in the `persistence.xml they are also set at the EntityManager, but if they are overwritten the new values aren't picked up.
It seems only the setQueryHint and the way over the persistence.xml is working.
Problem
A custom session timeout for queries -- like with the TransactionalTimeout annotation cannot be provided, as the values are ignored.
References
Payara Issue: https://github.com/payara/Payara/issues/4895 Example Project: https://github.com/sterlp/training/tree/master/jee-interceptor Eclipselink Version: Eclipse Persistence Services - 2.7.4.payara-p2
We are unable to configure the query timeout with 2.7.10. We tried via code, via persistence.xml and via configuring the EM and it does not work for us at all.
persistence.xml:
<properties>
<property name="javax.persistence.query.timeout" value="1000"/>
<!--
Eclipselink requires in addition this parameter
-->
<property name="eclipselink.query.timeout.unit" value="MILLISECONDS"/>
<property name="eclipselink.query.timeout" value="1000"/>
</properties>
Query:
TypedQuery<InvoiceSearch> qry = em.createQuery(sql, InvoiceSearch.class);
qry.setHint("eclipselink.refresh", "true");
qry.setHint("javax.persistence.query.timeout", "1000");
em.setProperty("eclipselink.query.timeout.unit", "MILLISECONDS"); // added for eclipse link support
em.setProperty("eclipselink.query.timeout", "1000"); // added for eclipse link support
qry.setHint("eclipselink.jdbc.timeout", "1000");
qry.setHint("eclipselink.query.timeout.unit", "MILLISECONDS");
qry.setHint(QueryHints.QUERY_TIMEOUT, "1000");
Properties for the EM:
private Map<String, Object> setPersistenceProperties(String user, String pw, String url) {
Map<String, Object> persistenceProperties = new HashMap<String, Object>();
// allgemeiner Teil
persistenceProperties.put(PersistenceUnitProperties.CLASSLOADER, getClass().getClassLoader());
persistenceProperties.put(PersistenceUnitProperties.JDBC_DRIVER, "oracle.jdbc.OracleDriver");
// ID_VALIDATION is used because ALLOW_ZERO_ID has been deprecated
persistenceProperties.put(PersistenceUnitProperties.ID_VALIDATION, IdValidation.NULL.name());
persistenceProperties.put(PersistenceUnitProperties.CACHE_TYPE_DEFAULT, "Soft");
persistenceProperties.put(PersistenceUnitProperties.LOGGING_LEVEL, SessionLog.SEVERE_LABEL);
persistenceProperties.put("eclipselink.query.timeout.unit", "MILLISECONDS");
persistenceProperties.put("eclipselink.jdbc.timeout", "10");
persistenceProperties.put("javax.persistence.query.timeout", "10");
// DB specifischer Teil
persistenceProperties.put(PersistenceUnitProperties.JDBC_USER, user);
persistenceProperties.put(PersistenceUnitProperties.JDBC_PASSWORD, pw);
persistenceProperties.put(PersistenceUnitProperties.JDBC_URL, url);
return persistenceProperties;
}
Is there something we are doing wrong?