Hi,
I need to execute a query in my native SQL dialect as I need to use a slightly unusual locking hint. I need to lock the selected row for update
and also read past any other row that is already locked for update. This way I can have multiple machines attempting to request the first item from the queue without any machine getting the same record as another.
In standard MS SQL I would do it like this (this has been somewhat simplified, but it would run in a transaction):
Code:
SELECT TOP 1 ItemID FROM Queue WITH (UPDLOCK, READPAST) WHERE QueueStatus = 0
UPDATE Queue SET QueueStatus = 1 WHERE ItemId = @ItemID"
Is there a way to do this from an NHibernate session? Or do I need to manually use the underlying connection to manage this?
Cheers,
Symon.