SetLockMode with IQuery and SQL Server

274 views
Skip to first unread message

Graham Bunce

unread,
Nov 23, 2009, 8:30:16 AM11/23/09
to nhusers
All,

Trying to use SetLockMode with an IQuery. I don't fully understand
what the alias means (documentation isn't that clear, could do with an
example) but I think it refers to the object being locked.

I have the following statement:

IDomainClassChild child = session.CreateQuery("FROM DomainClassChild
WHERE ChildName = :name")
.SetString("name", "Donna Nobel")
.SetMaxResults(1)
.SetLockMode(string.Empty, LockMode.Upgrade)
.UniqueResult<IDomainClassChild>();

and it fails with an NHibernate ADOException, message is:

could not execute query
[ select domainclas0_.Id as Id1_, domainclas0_.ParentId as ParentId1_,
domainclas0_.ChildName as ChildName1_, domainclas0_.Counter as
Counter1_ from DomainClassChild domainclas0_ where
domainclas0_.ChildName=? ]
Name:name - Value:Donna Nobel
[SQL: select domainclas0_.Id as Id1_, domainclas0_.ParentId as
ParentId1_, domainclas0_.ChildName as ChildName1_,
domainclas0_.Counter as Counter1_ from DomainClassChild domainclas0_
where domainclas0_.ChildName=?]

As far as I can tell, there isn't a lot wrong with the query NH has
produced.

I've also used the LockMode with "DomainClassChild" as the alias
instead of string.Empty, and as the internal NH created reference
"domainclas0" but no difference. If I take out the lock mode, the
query works.

What should this alias be... or how do I use LockMode on an IQuery?

Graham Bunce

unread,
Nov 24, 2009, 4:42:30 AM11/24/09
to nhusers
/bump

..... or any links to SetLockMode with a Query and what the alias
means? Google doesn't come up with much for Querys. There's quite a
lot for Criterion... does SetLockMode not actually work for a query?

The documentation says its IQuery.SetLockMode() whereas it is actually
IQuery.SetLockMode(string alias, LockMode mode)

Graham Bunce

unread,
Nov 25, 2009, 5:36:55 AM11/25/09
to nhusers
/bump

Anybody able to explain what the alias should be for an HQL based
IQuery?

Fabio Maulo

unread,
Nov 25, 2009, 7:40:52 AM11/25/09
to nhu...@googlegroups.com
luckily, nobody is answering... that mean there are very few people using it, as expected in ORM.
Well from API:
Set the lockmode for the objects idententified by the
given alias that appears in the <c>FROM</c> clause.

alias
a query alias, or this for a collection filter

s.CreateQuery("from Pizza p where p.Name= :pName").SetLockMode("p", LockMode.Upgrade).SetParameter("pName", "Quattro stagioni");

2009/11/25 Graham Bunce <graha...@hotmail.com>
/bump

Anybody able to explain what the alias should be for an HQL based
IQuery?

--

You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.





--
Fabio Maulo

Graham Bunce

unread,
Nov 25, 2009, 7:57:47 AM11/25/09
to nhusers
Thanks Fabio. Obvious in the end...:p

Usually I don't use it, but I'm trying to reproduce a bug and want to
force a database deadlock situation.....
Reply all
Reply to author
Forward
0 new messages