-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Return scalar values from SQLQuery?
PostPosted: Fri Nov 04, 2005 7:25 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 8:15 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Just use the underlying connection I would say... There's no benefit to using NHibernate in this case.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 10:41 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
No problem. I was just wondering whether if I used NHibernate for it then it would control the opening/closing of the connection and the transaction (if one were present).

I'm assuming that the connection for the session will be closed and there won't be a db transaction present unless I'm in the middle of an NHibernate transaction...is that right?

Cheers,

Symon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.