sql-servermultithreadinghibernatetable-locking

Hibernate with MS SQL Server 2012 issue with table locks and parallel query


I have a java thread that does the update of few tables in a transaction and there is another thread that reads the tables with read only transaction . The thread that reads the tables is waiting and not retuning the result and returns only after the other thread had done the update .

The case is different if DB is mysql where the update and query does happen parallel and no waiting . Am I missing something on MS SQL side . What needs to be done to make it parallel . Is this happening because of table locks in MS Sql Server .

The MS Sql server hibernate setting :

db.driverClassName = com.microsoft.sqlserver.jdbc.SQLServerDataSource

db.dialect = org.hibernate.dialect.SQLServer2008Dialect

Hibernate version : v4.3.6.Final

Connection pool : HikariCP-java6 - v2.2.5


Solution

  • in T-SQL you can use UNLOCK command, in this link you can see a full description of it. also you can use WITH (NOLOCK) while selecting from table like:

    SELECT *
    FROM sample_table WITH (NOLOCK)
    WHERE --conditions
    

    But in Hibernate with MS SQL Server I really don't know how to implement NOLOCK if you find a solution for it tell us I'll follow this question.