I meet the same issue just like the following:
NHibernate - not-null property reference a null or transient value
And the root reason is just like what Alun Harford said: "you're saving an entire object graph, and that graph is circular". see the following code
public class ApplyAuthorization : Activity
{
public virtual ApplyStatus Status { get; set; }
public virtual void Apply(Launch launch)
{
Status = Status ?? new ApplyStatus
{
For = this
};
Status.Update(launch);
}
}
So the relationship is bidirectional: ApplyAuthorization -(Status)-> ApplyStatus and at the same time ApplyStatus -(For)-> ApplyAuthorization.
Now I know the reason but how to handle it?