SetLockMode

114 views
Skip to first unread message

Steve Strong

unread,
Sep 22, 2010, 5:10:58 PM9/22/10
to nhibernate-...@googlegroups.com
Hi Chaps,

Just playing with adding support for LockModes to the Linq provider and wanted to get a quick view on it's expected operation.  For a simple HQL query such as

  var q = session.CreateQuery("select so from ScheduleOccurrence so");
  q.SetLockMode("so", LockMode.Force);

I have some corresponding Linq working:

  from so in session.Query<ScheduleOccurrence>().LockMode(LockMode.Force)
  select so;

I was then starting to look at locking on joins and discovered that the following HQL doesn't work:

  var q = session.CreateQuery("select so from ScheduleOccurrence so from ScheduleOccurrence so2 where so.Start = so2.End");

  q.SetLockMode("so2", LockMode.Force);

So the question is, should it? Is this a bug in the HQL parser or are lock modes on additional From clauses not supported?

Cheers,

Steve

Steve Strong

unread,
Sep 22, 2010, 5:27:22 PM9/22/10
to nhibernate-...@googlegroups.com
As Fabio spotted, I've written the 2nd hql query wrong - it should read:

  var q = session.CreateQuery("select so from ScheduleOccurrence so, ScheduleOccurrence so2 where so.Start = so2.End");

  q.SetLockMode("so2", LockMode.Force);

(I've spent so long dealing with the internal ASL for HQL that I'm forgetting what the string representation looks like!) Same behaviour with the locking though - it throws "{"could not locate alias to apply lock mode : so2"}"

Frans Bouma

unread,
Sep 22, 2010, 5:36:24 PM9/22/10
to nhibernate-...@googlegroups.com
(I have no idea how it works internally </disclaimer>)

could it be the lockmode setter logic is executed before aliases are
assigned? Also, if the entity is a target per entity (each entity a
different table) subtype, does it work then? (so real aliases are different)

FB

Graham Bunce

unread,
Sep 23, 2010, 7:16:25 PM9/23/10
to nhibernate-development
AFAIK this is a long standing bug with HQL.

NH-1968 for NH 3.0 but I've never managed to get it working all the
time in 2.1.x either. I've read it works fine in criteria queries
though...

Reply all
Reply to author
Forward
0 new messages