Hello,
we want to implement a relative big project (120 Data Objects) with nhibernate, the general functionality of nhibernate is clear ...
But a view thinks are a "bit cloudy":
We don't want to delete the data objects physicaly, it should only be set an object state:
General Table design:
table [xy]
pk -- guid, or autovalue of bigint
ostate int -- 0 default, 1 .. deleted
This means if i access a deleted data object (ostate==1) it should not be returned (return null)
Simplified example for a one to one relation:
Code:
[Serializable]
public class DataObject : IDataObject
{
private long _id;
public long Id
{
get { return _id; }
set { _id = value; }
}
private int _oState;
public int OState
{
get { return _oState; }
set { _oState = value; }
}
public override bool Equals(object obj)
{
Key key = obj as Key;
if (key != null && key._id == this._id && key.OState == this._oState)
return true;
return false;
}
public override int GetHashCode()
{
return _id.GetHashCode() ^ _oState.GetHashCode();
}
}
[Serializable]
public class DoWfObject : DataObject
{
private DoWfObjectData _data;
public DoWfObjectData Data
{
get { return _data; }
set { _data = value; }
}
public DoWfObject()
{
}
}
[Serializable]
public class DoWfObjectData : DataObject
{
private DoWfObject obj;
public DoWfObject Object
{
get { return _object; }
set { _object = value; }
}
public DoWfObjectData()
{
}
}
This means in the following scenario:
DoWfObject (ostate default)
DoWfObjectData (ostate deleted)
wfObject.Data should return null
I have tried it with several different meachnisms:
where attribute:
<class name="DoWfObject" table="WfObject" where="OState=0">
This constraint is only used for HQLs (in some cases), not for loading an object graph like DoWfObject.Data.
Composite-Id:
Code:
<composite-id>
<key-property name="Id" column="idWfObject" type="Int64" access="nosetter.camelcase-underscore"/>
<key-property name="OState" column="OState" type="Int32" access="nosetter.camelcase-underscore"/>
</composite-id>
...
<many-to-one insert="false" update="false" name="Object" not-null="true" class="DoWfObject" unique="true">
<column name="idObject"/>
<column name="'0'" />
</many-to-one>
This returns me some errors (i can provide you additional infos, if neccessary)
But i'm generally not sure if this is the right way.
Can anyone tell me if it is possible to implement such a mechanism with the current Nhibernate 1.0.2.0 version