Description
Sanjeev Sinha created an issue — 5th October 2017, 6:20:51:
As per the documentation, the class
<property>
insert
andupdate
attributes are optional and their default value istrue
.(4)
update, insert (optional - defaults to true) : specifies that the mapped columns should be included in SQL UPDATE and/or INSERT statements. Setting both to false allows a pure "derived" property whose value is initialized from some other property that maps to the same column(s) or by a trigger or other application.{quote}But when we deserialize .hbm file to
HbmClass
whose property is not set (that means it should betrue
by default) it showsfalse
value with theHbmProperty
'sinsert
andupdate
. This contradicts the documentation. Actually it should have beentrue
.Here is the actual places where changes needs to be done.
<xs:element name="property"> <xs:complexType> <xs:sequence> <xs:element ref="meta" minOccurs="0" maxOccurs="unbounded" /> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element ref="column" /> <xs:element ref="formula" /> </xs:choice> <xs:element ref="type" minOccurs="0" /> </xs:sequence> <xs:attribute name="name" use="required" type="xs:string" /> <xs:attribute name="node" type="xs:string" /> <xs:attribute name="access" type="xs:string" /> <xs:attribute name="type" type="xs:string" /> <xs:attribute name="column" type="xs:string" /> <xs:attribute name="length" type="xs:positiveInteger" /> <xs:attribute name="precision" type="xs:positiveInteger" /> <xs:attribute name="scale" type="xs:nonNegativeInteger" /> <xs:attribute name="not-null" type="xs:boolean"> </xs:attribute> <xs:attribute name="unique" default="false" type="xs:boolean"> </xs:attribute> <xs:attribute name="unique-key" type="xs:string" /> <xs:attribute name="index" type="xs:string" /> <!-- Here, missing default="true" on two next attributes --> <xs:attribute name="update" type="xs:boolean"> </xs:attribute> <xs:attribute name="insert" type="xs:boolean"> </xs:attribute> <xs:attribute name="optimistic-lock" default="true" type="xs:boolean"> </xs:attribute> <xs:attribute name="formula" type="xs:string" /> <xs:attribute name="lazy" default="false" type="xs:boolean"> </xs:attribute> <xs:attribute name="generated" default="never" type="propertyGeneration"> </xs:attribute> </xs:complexType> </xs:element>public HbmProperty() { this.unique = false; this.optimisticlock = true; this.lazy = false; this.generated = HbmPropertyGeneration.Never; // Here, lacking update and insert initialization. }As we know where to fix, so moderator will agree we can submit the solution.
Frédéric Delaporte added a comment — 5th October 2017, 11:46:19:
Your are welcome to contribute. Please make sure you follow guidelines from contributing.md file. You already have the Jira, which is great.
About tests, there are already some tests about those properties, like
WhenSetUpdateThenSetAttributes
inNHibernate.Test.MappingByCode.MappersTests.PropertyMapperTest
. So it seems some tests are missing, and need to be added.About the classes, they are generated code. Avoid editing them manually. Instead follow How to generate Hbm.generated.cs.txt.
It should be noted that the actual feature provided by those
update
andinsert
attribute still works as expected even when they are not set, treating them as if they weretrue
, because the feature checks if they were explicitly defined, and if no, disregards their actual value and considers themtrue
.Now for correctness it would still be better to have their default value correctly set in the xsd schema.