I'm trying to use LockMode to make sure the entity I get through my session
locks the row(s) in the database. However, the generated SQL (for MS SQL
Server) appears to only be locking the base row. This leads to deadlocks
when NHibernate eventually updates the properties in the subclass mapping
to the child table's row.
I fetch the entity through the session like this:
CustomerOrder myCustomerOrder =
mySession.Get<CustomerOrder>(myCustomerOrderId, LockMode.Upgrade);
Customer order is a subclass of the Order base class, mapped with
table-per-subclass:
class Order {} // tblOrders
class CustomerOrder : Order {} // tblCustomerOrders
The generated SQL (observed via NHProf) is:
SELECT ...
FROM dbo.tblOrders customeror0_ *with (updlock, rowlock)*
inner join dbo.tblCustomerOrders customeror0_1_
on customeror0_.OrderID = customeror0_1_.OrderIDID
What I *think* I need is for the "(updlock, rowlock) to also follow
tblCustomerOrders (here's one source:
http://stackoverflow.com/questions/2577337/can-i-lock-a-record-from-a-join-sql-statment-using-rowlock-updlock
).
So if that is what is needed so that the *entity* is locked, shouldn't
NHibernate be doing this?
--
Regards,
Brian.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.