Hi,

I am sending this to the development mailing list because it is a
question for the people who think NHibernate and who implement it, not
the ordinary users.
I have an Order entity with a collection of OrderLines. All mapped
with the defaults, generated with the new API. The OrderLines set is
lazy loaded.
If I load an Order and then access its OrderLines, everything is fine.
But I noticed that each of the OrderLine items has LockMode.Read, and
I think it should be None, because I am not locking it in any way, at
least, explicitly.

The classes are:

public class Order
{
    public virtual Int32 Id { get; set; }
    public virtual DateTime Date { get; set; }
    public virtual String Customer { get; set; }
    public virtual ISet<OrderLine> OrderLines { get; set; }
}

public class OrderLine
{
    public virtual Int32 Id { get; set; }
    public virtual String Product { get; set; }
    public virtual Int32 Count { get; set; }
    public virtual Order Order { get; set; }
}

As you can see, it is a simple model, just to illustrate the problem.
And the test code:

using (var session = factory.OpenSession())
using (session.BeginTransaction())
{
        var order = session.Get<Order>(1);
        order.OrdersLines.ToArray();

        var orderMode = session.GetCurrentLockMode(order);  //Read
        var orderLineMode =
session.GetCurrentLockMode(order.OrdersLines.First());  //Read
}

Now, if I don't use a transaction, order is not locked, but the
OrderLines remain:

using (var session = factory.OpenSession())
{
        var order = session.Get<Order>(1);
        order.OrdersLines.ToArray();

        var orderMode = session.GetCurrentLockMode(order);  //None
        var orderLineMode =
session.GetCurrentLockMode(order.OrdersLines.First());  //Read
}

If I map OrderLines as not lazy with join fetch mode, if I use the
transaction, they still have LockMode.Read, if I don't, they have
LockMode.None.
Some time ago I already asked if this was normal, and I was even with
the impression that at some pre-3.2.0GA version, it was fixed, but now
it is happening again.
So, is this the normal behavior, or is it a bug?

Thanks!

RP

Reply via email to