Browse Source

Transaction timeouts for JPA translate to "javax.persistence.query.timeout" only (for EclipseLink compatibility)

Issue: SPR-10068
pull/196/head
Juergen Hoeller 13 years ago committed by unknown
parent
commit
184361a096
  1. 20
      spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java

20
spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java

@ -254,8 +254,7 @@ public abstract class EntityManagerFactoryUtils { @@ -254,8 +254,7 @@ public abstract class EntityManagerFactoryUtils {
/**
* Apply the current transaction timeout, if any, to the given JPA Query object.
* <p>This method sets the JPA 2.0 query hints "javax.persistence.lock.timeout"
* and "javax.persistence.query.timeout" accordingly.
* <p>This method sets the JPA 2.0 query hint "javax.persistence.query.timeout" accordingly.
* @param query the JPA Query object
* @param emf JPA EntityManagerFactory that the Query was created for
*/
@ -263,17 +262,11 @@ public abstract class EntityManagerFactoryUtils { @@ -263,17 +262,11 @@ public abstract class EntityManagerFactoryUtils {
EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource(emf);
if (emHolder != null && emHolder.hasTimeout()) {
int timeoutValue = (int) emHolder.getTimeToLiveInMillis();
try {
query.setHint("javax.persistence.lock.timeout", timeoutValue);
}
catch (IllegalArgumentException ex) {
// oh well, at least we tried...
}
try {
query.setHint("javax.persistence.query.timeout", timeoutValue);
}
catch (IllegalArgumentException ex) {
// once again, at least we tried...
// oh well, at least we tried...
}
}
}
@ -283,11 +276,10 @@ public abstract class EntityManagerFactoryUtils { @@ -283,11 +276,10 @@ public abstract class EntityManagerFactoryUtils {
* <code>org.springframework.dao</code> hierarchy.
* Return null if no translation is appropriate: any other exception may
* have resulted from user code, and should not be translated.
* <p>The most important cases like object not found or optimistic locking
* failure are covered here. For more fine-granular conversion, JpaAccessor and
* JpaTransactionManager support sophisticated translation of exceptions via a
* JpaDialect.
* @param ex runtime exception that occured
* <p>The most important cases like object not found or optimistic locking failure
* are covered here. For more fine-granular conversion, JpaTransactionManager etc
* support sophisticated translation of exceptions via a JpaDialect.
* @param ex runtime exception that occurred
* @return the corresponding DataAccessException instance,
* or <code>null</code> if the exception should not be translated
*/

Loading…
Cancel
Save