Version: Nhibernate 1.2b3.
I have a composite key (2 columns) that has one-to-one mapping to child table and further. The one-to-one relation continues over 3 or 4 tables down and back (bidirectional).
The column names differ from table to table.
I have tested now on 2 tables with a helper class "ObjItemStatComp".
When I load the tables my primary key is 0 (HQL: Select o from ObjItemstat o).
Where's the trick to get it working?
Parent table:
<class name="C2.DAL.DaoObjects.ObjItemStat,C2" table="OBJ_ITEM_STAT" lazy="true">
<!-- Created composite-id element for primary-keys. -->
<composite-id access="field" class="C2.DAL.DaoObjects.ObjItemStatComp,C2">
<key-property name="ObjItemId" column="OBJ_ITEM_ID" type="Decimal" />
<key-property name="ObjItemStatIx" column="OBJ_ITEM_STAT_IX" type="Decimal" />
</composite-id>
<one-to-one name="FacStatChild" class="C2.DAL.DaoObjects.FacStat,C2" />
...
</class>
--------------------------
Child table:
<class name="C2.DAL.DaoObjects.FacStat,C2" table="FAC_STAT" lazy="true">
<!-- Created composite-id element for primary-keys. -->
<composite-id access="field" class="C2.DAL.DaoObjects.ObjItemStatComp,C2">
<key-property name="ObjItemId" column="FAC_STAT_ID" type="Decimal" />
<key-property name="ObjItemStatIx" column="OBJ_ITEM_STAT_IX" type="Decimal" />
</composite-id>
<!-- Second part of one-to-one element of composite-id. -->
<one-to-one name="ObjItemStatParent" class="C2.DAL.DaoObjects.ObjItemStat,C2" constrained="true" />
...
</class>
------------------------------------
[Serializable]
public class ObjItemStatComp
{
#region Private Members
private Decimal m_obj_item_stat_ix;
private Decimal m_obj_item_id;
#endregion // Private Members
#region Default ( Empty ) Class Constructor
public ObjItemStatComp()
{
m_obj_item_stat_ix = 0;
m_obj_item_id = 0;
}
#endregion // End of Default ( Empty ) Class Constructor
#region Public Properties
public virtual Decimal ObjItemStatIx
{
get { return m_obj_item_stat_ix; }
set { m_obj_item_stat_ix = value;
}
}
public virtual Decimal ObjItemId
{
get { return m_obj_item_id; }
set { m_obj_item_id = value;
}
}
#endregion // Public Properties
#region Equals And HashCode Overrides
public override bool Equals( object obj )
{
if( this == obj ) return true;
if( ( obj == null ) || ( obj.GetType() != this.GetType() ) ) return false;
ObjItemStatComp castObj = (ObjItemStatComp)obj;
return ( castObj != null ) &&
( this.m_obj_item_stat_ix == castObj.ObjItemStatIx ) &&
( this.m_obj_item_id == castObj.ObjItemId );
}
public override int GetHashCode()
{
int hash = 57;
hash = 27 * hash * m_obj_item_stat_ix.GetHashCode();
hash = 27 * hash * m_obj_item_id.GetHashCode();
return hash;
}
#endregion
}
|