After setting the default transaction timeout on my JPATransactionManager to ensure any blocked transactions get killed, I have noticed some transactions being killed immediately as soon as they start. It doesn't always happen, just for some of them.
It appears as though the transaction timeout deadline is sometimes being inherited from a previous transaction, or is not being independently set. e.g. in the case below, the previous transaction started at 19.09, with a timeout of 30 mins. It completed successfully. But at 7.00 next morning a timed job kicks off (in a new transaction), and fails immediately stating that the timeout deadline of 19.39 has passed.
2014-02-20 07:00:12.602Z ERROR Transaction timed out: deadline was Wed Feb 19 19:39:45 UTC 2014 INFO | jvm 1 | 2014/02/20 07:00:12 | org.springframework.transaction.TransactionTimedOutException: Transaction timed out: deadline was Wed Feb 19 19:39:45 UTC 2014 INFO | jvm 1 | 2014/02/20 07:00:12 | at org.springframework.transaction.support.ResourceHolderSupport.checkTransactionTimeout(ResourceHolderSupport.java:141) ~[spring-tx-3.1.1.RELEASE.jar:3.1.1.RELEASE]
Is there a property I am missing, or a known bug?
I suspected not releasing the session might be an issue so I tried adding what hibernate properties looked relevant on the entity manager factory but they made no difference (and I think should be default behaviour anyway?)
Config:
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() throws SQLException { final LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean(); bean.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); bean.setDataSource(dataSource()); bean.setJpaDialect(new HibernateJpaDialect());
final Map<String, String> jpaPropertyMap = new HashMap<String, String>(); jpaPropertyMap.put("hibernate.connection.release_mode", "after_transaction"); jpaPropertyMap.put("hibernate.current_session_context_class", "thread");
bean.setJpaPropertyMap(jpaPropertyMap); bean.setPersistenceUnitName(PERSISTENCE_UNIT_NAME); return bean; }
@Bean public PlatformTransactionManager transactionManager() throws SQLException { JpaTransactionManager transactionManager = new JpaTransactionManager(entityManagerFactoryBean().getObject()); transactionManager.setDefaultTimeout(transactionTimeoutSeconds);
return transactionManager; }
Thx for any help, Mark
|