开发者

NHibernate mapping does not populate the bag

<class name="CashThreshold" table="CASH_THRESHOLD_COUNTERS" lazy="true" >
<id name="Id" column="ID" >
  <generator class="assigned" />
</id>
<bag name="ThresholdNominalsList" cascade="all" inverse="true" lazy="false" table="CASH_THRESHOLD_CAS_COUNTERS">
  <key column="CASH_THRESHOLD_ID" />
  <one-to-many class="NominalThreshold" />
</bag>

Map second table

<class name="NominalThreshold" table="CASH_THRESHOLD_CAS_COUNTERS" lazy="true" >
<composite-id>
  <key-property name="CashTrasholdId" column="CASH_THRESHOLD_ID" type="long"></key-property>
  <key-property name="Nominal" column="NOMINAL" type="long"></key-property>
</composite-id>

<property name="MinNoteCount" column="MIN_NOTE_COUNT" />
<property name="MaxNoteCount" column="MAX_NOTE_COUNT" />

Table classes

public class CashThreshold : ICashThreshold
{
    public virtual long Id { set; get; }

    /// !!!!!!! IS ALWAYS AMPTY, but not null !!!!!
    public virtual IList<INominalThreshold> ThresholdNominalsList { set; get; }
}

public class NominalThreshold : INominalThreshold
{
    public virtual long CashTrasholdId { set; get; }
    public virtual long Nominal { set; get; }
    public virtual long MinNoteCount { set; get; }
    public virtual long MaxNoteCount { set; get; }

    public override bool Equals(Object obj)
    {
        var tmp = (INominalThreshold)obj;
        return (tmp.CashTrasholdId == CashTrasholdId && tmp.Nominal == Nominal);
    }

    public override int GetHashCode()
  开发者_如何学编程  {
        return (int)CashTrasholdId ^ (int)Nominal;
    }
}

Function for getting list of ICashThreshold

        ICriteria selectAll = currentSession.CreateCriteria<ICashThreshold>();

        IList<ICashThreshold> list = selectAll.List<ICashThreshold>();

Query executed whith no errors. Bag-query executed successfully in sql-client and returned 4 result, but IList< INominalThreshold > ThresholdNominalsList has no elements.

Thanks.


Problem solved. NHibernate mapped bag successfully, but list was empty, because the data in DB was NOT COMMITTED. I inserted test data in the table, but did not commit it. When I execute query in sql-client, it executed successfully(because do it in session, where table rows inserted), but hibernate had another session. Thats why NHibernate could not see the table data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜