karlchu wrote:
What you have here, essentially, is a bidirectional one-to-many association regardless of the fact that it is a self join. As such, all rules and conventions that surround a bidirectional one-to-many association apply. One thing that I spotted is that the mapping of the SubjectedClasses property should be inversed (i.e. inverse="true"). Therefore, it will not be enough to just put objects into the SubjectedClasses; their OwnerClass will not be automatically set. In other words, you need to somehow set the OwnerClass property yourself before saving.
Hope this helps.
Thanks Karl, but none of your advices help. I tried to add inverse="true". I tried to set OwnerClass manually ever before. The problem is the same: in the database ClassOwner is still NULL.
I have the following code when I try to save my objects now:
Code:
using (ISession nsess = _factory.OpenSession())
{
foreach (Class1 cfg in _session.SessionCfg)
{
if (cfg.OwnerClass != null)
nsess.SaveOrUpdate(ccfg.OwnerClass);
nsess.SaveOrUpdate(ccfg);
}
}
Mapping now is as follows:
Code:
<class name="Class1" table="ClassConfiguration" lazy="false">
<id name="ClassId" column="ClassId">
<generator class="native" />
</id>
<list name="SubjectedClasses" table="ClassConfiguration" lazy="false" cascade ="all" inverse="true">
<key column="OwnerClassConfiguration"/>
<index column="ClassConfigurationId"/>
<one-to-many class="ClassConfiguration"/>
</list>
</class>
May the problem be in wrong mapping of key and index? Or what direction I shall try to dig?
Thanks in advance.