There's a Hibernate bug, HHH-5436
(https://hibernate.onjira.com/browse/HHH-5436) that seems related. That
bug highlights that within a dialect (Oracle, in the case of the bug
author) it does not consistently apply locks to joined-subclass tables
depending on whether you get with the lock up front, or get without a lock,
and then lock it later. Thus, at the very least, the OracleXxxDialect is
violating John Davidson's assertion that the subclass table is never locked.
Now I've considered writing a custom dialect, subclassing the
MsSql2008Dialect, that tweaks things just enough to accomplish what I want
-- locking the base class table *and* subclass table (going against John
Davidson's assertion). However, after tinkering around with the dialect
usage via a debugger, I don't think this is possible. I believe it is the *
AbstractEntityJoinWaller*'s *InitStatementString* method that is building
the sql-select statement and appending the lock hint only to the *first*
(base?)
table. So I can't simply modify the dialect and make it work.
On Monday, January 7, 2013 10:34:26 AM UTC-5, Trinition wrote:
>
> 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 view this discussion on the web visit
https://groups.google.com/d/msg/nhusers/-/AX585aSQF7sJ.
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.