简体   繁体   English

发生异常时,如何在休眠状态下解锁记录?

[英]How can I unlock a record in hibernate when exception occurs?

I locked a record by using get(Classname.class, Serizelbea , LOCKOPTIONS) in Hibernate but an exception occurred, and I want to unlock this record. 我在Hibernate中使用get(Classname.class,Serizelbea,LOCKOPTIONS)锁定了一条记录,但发生了异常,我想解锁该记录。 I have searched in the Internet but I haven't found any method to resolve this problem. 我在Internet上进行了搜索,但没有找到解决此问题的任何方法。

Please help me 请帮我

I'm pretty sure that an evict releases all locks that could exist on an object. 我非常确定, evict会释放对象上可能存在的所有锁。 If not, it would be a serious problem because Hibernate will keep a lock on a object it no longer knows. 如果不是这样,那将是一个严重的问题,因为Hibernate会锁定一个不再知道的对象。

And is you want to be able to access the record later you can do another get but without lock. 如果您希望以后能够访问记录,则可以进行另一次get但没有锁定。

The only problem, is that it could be tedious if you want to test that the lock is really released. 唯一的问题是,如果您想测试该锁是否真正释放,可能会很乏味。

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

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