Version does not increase when updating child

If I read the documentation correctly, if I have an Order object mapped to a version column (with the addition of nhibernate), then changes in the order lines should update the version number for the aggregate (Order) root. This really does this when I add / delete order lines, but if I only change, for example, the quantity in an ordered line, then the version of the order is not updated. Is this expected behavior?

I checked the source of NH, and it seems that it only checks dirty collections, trying to determine if an increment increase is needed, and the collection will be dirty when adding / removing items, and not if any item in the collection is dirty.

I have the following mapping:

public class OrderMap : ClassMap<Order> { public OrderMap() { Id(c => c.Id).GeneratedBy.GuidComb(); Version(c => c.Version); OptimisticLock.Version(); HasMany(x => x.OrderLines) .Inverse() .Cascade.AllDeleteOrphan(); } } public class OrderLineMap : ClassMap<OrderLine> { public OrderLineMap() { Id(x => x.Id).GeneratedBy.GuidComb(); Map(x => x.Quantity); References(x => x.Order); } } 

So my question is if this is the expected behavior? That is, this version will not be updated when children are changed only when the child collection is changed using remove / add. This kind of breaks down the general structure of the root concurrency.

+4
source share
1 answer

This is really the expected behavior. There is a way to solve this problem with an event listener that can detect changes in children and go to the root node and block it optimistically (causing a version change).

Additional information in this post from Ayende: http://ayende.com/blog/4055/nhibernate-automatic-change-tracking-for-aggregate-roots-in-ddd-scenarios

+3
source

Source: https://habr.com/ru/post/1383599/


All Articles