Locks in NHibernate

1,291 views
Skip to first unread message

raphy

unread,
Dec 14, 2010, 3:07:15 PM12/14/10
to nhusers
I use NHibernate since 2 years now, I’ve pretty always managed to do
what I want, but now, I’m stuck !

Our app is in production since February, and now we’re having
performance problem.

One of our developer here told us to try to add nolock hints to our
sql queries issued by NHibernate. (We use a MSSQL 2008 db)

I’ve come across NHibernate source code (2.1.2) and I’ve not find any
nolock word in whole solution ! I already know about
IsolationLevel.ReadUncommitted but ….
In Nhibernate I see a method called SetLockMode in the criteria API
(I’ve already tested this) , but I see no difference according to
lockmode I choose … (moreover, there is a nullexception when i use
setlockmode with no alias in a projection, i'll post late about this)

My question(s) are :
Except from doing sql-query, is there any way to issue a query that
doesn’t lock, in any way (read, update, etc…) the table ?
Maybe I already do sql queries that are OK, but I have no tool to
verify this ; I’ve used NHProf, but I don’t see anything concerning
locks.

Another thing is projections. I’ve managed to use projections on
server side (we have a pretty complex object graph (about 5 levels …))
to do slight select ; can I use something like this for my updates ?



Thank you all !

Raphy

Oskar Berggren

unread,
Dec 14, 2010, 4:51:02 PM12/14/10
to nhu...@googlegroups.com
2010/12/14 raphy <rapha...@gmail.com>:

> I use NHibernate since 2 years now, I’ve pretty always managed to do
> what I want, but now, I’m stuck !
>
> Our app is in production since February, and now we’re having
> performance problem.
>
> One of our developer here told us to try to add nolock hints to our
> sql queries issued by NHibernate. (We use a MSSQL 2008 db)

This seems a bit trial-and-errorish... Do you actually know which
query or update is causing the problem, or do you just want to
experiment?

With nolock you may see uncommitted transactions it seems. Is that
really acceptable?

Maybe the READ_COMMITTED_SNAPSHOT database option is interesting?
See http://msdn.microsoft.com/en-us/library/ms188277.aspx

/Oskar

allan....@gmail.com

unread,
Dec 14, 2010, 8:01:26 PM12/14/10
to nhusers
You can do perform a query that is equivalent to adding nolock by
using the following:

using (var transaction =
session.BeginTransaction(IsolationLevel.ReadUncommitted)) {
.. query here
}

On Dec 14, 4:51 pm, Oskar Berggren <oskar.bergg...@gmail.com> wrote:
> 2010/12/14 raphy <raphabit...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages