Skip to content

Commit

Permalink
Stop NHibernate from retrieving the ChangeVersion after every INSERT …
Browse files Browse the repository at this point in the history
…and UPDATE statement for the aggregate root entities.
  • Loading branch information
gmcelhanon committed Sep 21, 2024
1 parent ad658d2 commit 023d751
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ public void Execute(object sender, BindMappingEventArgs e)

// Maps the ChangeVersion column dynamically
// Requires there be a property on the base entity already
// nHibernate wraps property getter exception in PropertyAccessException if any
// NHibernate wraps property getter exception in PropertyAccessException if any
// underlying mapped properties are set to access "none", due to an invoke exception being triggered.
// generated = "always" to avoid nHibernate trying to set values for it
// <property name="ChangeVersion" column="ChangeVersion" type="long" not-null="true" generated="always" />
// generated = "never" to prevent NHibernate trying to retrieve the value for it after insert or update
// insert = false to never include it in an INSERT statement
// update = false to never include it in an UPDATE statement
// <property name="ChangeVersion" column="ChangeVersion" type="long" not-null="true" generated="never" insert="false" update="false" />
var changeVersionProperty = new HbmProperty
{
name = ChangeQueriesDatabaseConstants.ChangeVersionColumnName,
Expand All @@ -47,7 +49,9 @@ public void Execute(object sender, BindMappingEventArgs e)
name = "long"
},
notnull = true,
generated = HbmPropertyGeneration.Always
generated = HbmPropertyGeneration.Never,
insert = false,
update = false,
};
classMapping.Items = classMapping.Items.Concat(changeVersionProperty).ToArray();
}
Expand Down

0 comments on commit 023d751

Please sign in to comment.