I have a Component class that can have SubComponents. I'm inheriting an old schema and it appears that a Component that has a ParentId of 0 instead of null means that it has no parent. I get an exception when it tried to load a Component with an Id of 0:
Code:
Unhandled Exception: NHibernate.UnresolvableObjectException: No
row with the given identifier exists: 0, of class: BOM.Component
at NHibernate.Impl.SessionImpl.InternalLoad(Type clazz, Object id)
All I'm doing is attempting to load a Component that has a ParentId of 0. Is there a way that I'm missing to specify that a value of 0 or whatever is equivalent to null so that it doesn't try to load an object with that Id?
My mapping:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo">
<class name="BOM.Component, BOM" table="COMPONENTS">
<id name="_Id" type="Int32" column="ComponentId" access="field">
<generator class="assigned" />
</id>
<many-to-one name="Parent" column="ParentId" class="BOM.Component, BOM" />
<property name="Description" column="ComponentDescription" type="String" />
<many-to-one name="TypeCode" column="TypeCode" class="BOM.TypeCode, BOM" />
<property name="DataTypeValue" column="DataTypeValue" type="Int32" />
<property name="KeyIndicator" column="KeyInd" type="Int32" />
<bag name="AssetComponents" inverse="true">
<key column="ComponentId" />
<one-to-many class="BOM.AssetComponent, BOM" />
</bag>
<bag name="AssetStickyComponents" inverse="true">
<key column="COMPONENTID" />
<one-to-many class="BOM.AssetStickyComponent, BOM" />
</bag>
<bag name="KeyAssetStickyComponents" inverse="true">
<key column="KEYCOMPONENTID" />
<one-to-many class="BOM.AssetStickyComponent, BOM" />
</bag>
<bag name="SubComponents" inverse="true" >
<key column="ParentId"/>
<one-to-many class="BOM.Component, BOM" />
</bag>
</class>
</hibernate-mapping>
Thx...
benster