首页 > 解决方案 > 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.

Here is a screenshot:

Transaction Report

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. 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?

标签: sqlsql-serverspringhibernatetransactions

解决方案


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. 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. 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.


推荐阅读