您知道如何设置 EntityManager.persist()
操作所遵守的事务超时吗? TransactionTemplate.setTimeout()
在插入记录期间似乎完全被忽略。在我的应用程序中,事务可能会尝试将行插入到被另一个线程锁定的表中。我想跳过等待这个锁并在应用程序中报告它。
我尝试启动单独的线程,这会中断事务的线程,但 oracle 驱动程序会忽略中断。您知道 hibernate 中事务超时的可靠机制吗?
最佳答案
我发现的一个解决方案是使用
((SessionImpl) entityManager.unwrap(Session.class))
.connection()
.setNetworkTimeout(timeoutCleanupExceutor, (timeoutInSeconds + 1) * 1000)
它并不漂亮,但它是唯一在忽略 TransactionTemplate.setTimeout()
时有效的替代方案。
关于java - Hibernate和Oracle中的事务超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59052551/