Proplem deleting objects from collection using NHibernate and C#

Answered Proplem deleting objects from collection using NHibernate and C#

  • Wednesday, May 20, 2009 5:06 PM
     
     

    Hi,

    I've a problem
    deleting object in a collection thru NHibernate call. I've a main object (ContentPlanItem) which contains some collection of objects (in parent - child relationship) say 'ContentPlanItemPayOffers' and 'ContentPlanItemCostCodes'

    I'm adding/deleting some items from the 'ContentPlanItemCostCodes' and 'ContentPlanItemPayOffers' collection which is a part of ContentPlanItem object.

    Now I'm simply sending ContentPlanItem object to NHibernate to perform save, expecting it would also save changes made in the child collections (as
    cascade="all-delete-orphan" is marked in parent .hbm.xml mapping) e.g. 'ContentPlanItemCostCodes' and 'ContentPlanItemPayOffers' but it throws the following exception:

     

    ‘Unexpected 0 Expected 1’

     

    The exception is raised because of the child collections.

     

    Original NHibernate Mapping of the parent class:

     

    <?xml version="1.0" encoding="utf-8" ?>

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"

    <class name="ContentPlanItem" table="CONTENT_PLAN_ITEM">

        <id name="Id" type="Int32">

          <column name="Id" sql-type="NUMBER" not-null="true"/>

          <generator class="sequence">

            <param name="sequence">CONTENT_PLAN_ITEM_SEQ</param>

          </generator>

        </id>

        <bag name="ContentPlanItemPayOffers" access="field.camelcase-underscore" cascade="all-delete-orphan" inverse="true" lazy="false">

          <key column="CONTENT_PLAN_ITEM_ID"/>

          <one-to-many class="ContentPlanItemPayOffer"/>

        </bag>

        <bag name="ContentPlanItemCostCodes" access="field.camelcase-underscore" cascade="all-delete-orphan" inverse="true" lazy="false">

          <key column="CONTENT_PLAN_ITEM_ID"/>

          <one-to-many class="ContentPlanItemCostCode"/>

        </bag>   

      </class>

    </hibernate-mapping>

     

    Any help would be much appreciated.

     

    Thanks,

    Nripen


     

    • Moved by Harry Zhu Friday, May 22, 2009 1:25 AM I'm moving the thread relating to NHibernate to Where is the Forum For ... forum. (From:Visual C# General)
    •  

All Replies