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
-
Wednesday, May 02, 2012 5:34 AMOwner
Does it fit in one of the other C# forums? http://social.msdn.microsoft.com/Forums/en-US/category/visualcsharp
Otherwise we need more info. Thanks!
Ed Price (a.k.a User Ed), SQL Server Experience Program Manager (Blog, Twitter, Wiki)
- Proposed As Answer by Ed Price - MSFTMicrosoft Employee, Owner Wednesday, May 02, 2012 5:34 AM
- Marked As Answer by Ed Price - MSFTMicrosoft Employee, Owner Wednesday, May 02, 2012 5:34 AM