[英]Hibernate + SQL Server: One Transaction blocks all other transactions
I am developing a server application with Spring + Hibernate + SQL-Server and i recognized that all my transactions are blocking other transaction, even if other transactions do not touch the same tables / rows and there are no relationships between this tables.我正在使用 Spring + Hibernate + SQL-Server 开发服务器应用程序,并且我认识到我的所有事务都在阻止其他事务,即使其他事务没有触及相同的表/行并且这些表之间没有关系。
Here is a screenshot:这是一个屏幕截图:
The screenshot shows that a delete statement on table A blocks a select statement on table B. But there is no relationship between the tables.截图显示A表的delete语句阻塞了表B的select语句,但是表之间没有关系。 In my understanding a transaction should only lock a table or row and another transactions that will hit the locked table or row will be blocked.
根据我的理解,一个事务应该只锁定一个表或行,而另一个将命中锁定的表或行的事务将被阻止。 But why are all transactions blocked?
但为什么所有交易都被阻止? Do i missunderstand anything?
我误解了什么吗?
Solution was found:找到了解决办法:
The process was a copy-process.这个过程是一个复制过程。 At the beginning i opened a transaction for the whole process and copy n-objects in this process.
一开始我为整个过程打开了一个事务,并在这个过程中复制了 n 个对象。 When i need to do selects while copying the selects were blocked.
当我需要在复制选择时进行选择时被阻止。 So i decide to open a transaction everytime i copy one object and after that copying-process close the transaction for this one object.
所以我决定每次复制一个对象时打开一个事务,然后在复制过程之后关闭这个对象的事务。 So selects are no longer blocked.
所以选择不再被阻止。 This design is like the copy-process in Windows.
这种设计就像 Windows 中的复制过程。 If you decide to cancel the copy-process the already copied files will stay.
如果您决定取消复制过程,则已复制的文件将保留。 Like in my case the already copied objects will stay cause the transaction was closed and committed for every object separatly.
就像在我的情况下,已经复制的对象将保留,因为事务已关闭并为每个对象单独提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.