简体   繁体   English

Hibernate 和 Oracle 中的事务超时

[英]Transaction timeout in hibernate and Oracle

Do You know how to set timeout for transaction which will be respecte by EntityManager.persist() opeartion?您知道如何设置EntityManager.persist()操作将尊重的事务超时吗? TransactionTemplate.setTimeout() seems to be completely ignored during inserting records. TransactionTemplate.setTimeout()在插入记录期间似乎被完全忽略了。 In my application it is possible that transaction tries to insert row to table which is locked by another thread.在我的应用程序中,事务可能会尝试将行插入到被另一个线程锁定的表中。 I would like to skip waiting for this lock and report it in application.我想跳过等待这个锁并在应用程序中报告它。

I tried to start separate thread which will interrupt transaction's thread, but interruption is ignored by oracle driver.我试图启动将中断事务线程的单独线程,但 oracle 驱动程序忽略了中断。 Do You know any reliable mechanizm for transaction timeout in hibernate?您知道休眠中事务超时的任何可靠机制吗?

One solution I found is to use我发现的一种解决方案是使用

((SessionImpl) entityManager.unwrap(Session.class))
    .connection()
    .setNetworkTimeout(timeoutCleanupExceutor, (timeoutInSeconds + 1) * 1000)

It is not pretty, but it is only alternative which works if TransactionTemplate.setTimeout() was ignored.它并不漂亮,但它只是在TransactionTemplate.setTimeout()被忽略时有效的替代方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM