One-to-one mapping behaviour change with Version 5.4.0 #3204
-
We wanted to Update to Nhibernate 5.4.0 but realized that the behaviour changed when updating parent/child relations on one-to-one mappings. Until Nhibernate 5.3.14 the version property of the parent did not change when adding a child. When debugging Nhibernate 5.3.14 there were two EntityInsertActions one for the Parent and one for the child. Now with 5.4 there are three, two EntityInsertActions for the parent and child and one EntityUpdateActions for the parent. Maybe i can illustrate our finding with a test: We have two Entitys, HasOneParent & HasOneChild
For these two we have the following mapping (Using FluentNhibernate)
And the mapping for the version and Id
Now in our test we want to create HasOneParent in a session, then in a second session we want to add a child.
This behaviour can be rectified if we use a method on the parent to update the relation, instead of directly accessing the property like:
Now the question is if our implementation is wrong and we should use a method for the update action, or if something changed in the new Nhibernate version. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Behavior is changed by implementing proper caching for one-to-one association #2576 In 5.4.1+ restore old behavior by setting public HasOneParentMap()
{
this.HasOne(x => x.Child)
.PropertyRef(x => x.Parent)
.Not.OptimisticLock() //<-- added code
.Cascade.All(); From one-to-one xml mapping doc:
|
Beta Was this translation helpful? Give feedback.
Behavior is changed by implementing proper caching for one-to-one association #2576
In 5.4.1+ restore old behavior by setting
optimistic-lock="false"
forone-to-one
mapping (.Not.OptimisticLock()
in Fluent NHibernate):From one-to-one xml mapping doc: