Following DDD, I've tried to apply
coarsed-grained locking with NHibernate on Aggregate Roots. No matter
if I use complex pattern to enforce Aggregate consistency in memory or
not, what I want is that if a child entity of an Aggregate is modified
and is requested to be saved by mistake (should save at the aggregate
root level), NHibernate will cascade the change back to the Aggregate
Root, whose version number will always be updated. This way, I think
that we would have 'cheap' coarsed-grained locking.
Unfortunately, when I declare "cascade='save-update'" on my
"many-to-one" relations from child entity to parent entity (up to the
Aggregate Root), NHibernate doesn't take it into account ... when I try
to save a modified child entity directly, NHibernate will update the
child table only, but not the table corresponding to the Aggregate Root.
Problem is : NHibernate sees that my Aggregate Root is non modified
and as such, doesn't issue any update statement. I've tried hacking up
the IInterceptor but I didn't get any success there.
Any ideas ?
Thanks in advance,
Steve Degosserie
PS : I'm using the trunk version of NH.