in many to many collection inserting a new child, its deleting all existing rows and re-generating all with new id
how to avoid this ? On Apr 7, 5:57 pm, Vels <[email protected]> wrote: > Hi.. > if i use all-delete-orphans and > > MasterItemList.remove(Masteritem1) > :session.update(MasterCategory) > :trans.Commit() > its removing from tblCategories and tblCategorisedItems too. i want to > remove only from tblCategorisedItems > > (all-delete-orphans working with one-to-many perfectly) > > So i changed little my Mapping information as : > > <bag name="MasterItemList" table="tblCategorisedItems" lazy="true" > collection-type="Collection.ObservableList`1 > [[emPowerBO.MasterItem, emPowerBO]], Collection"> > <key column="CategoryCode"/> > <many-to-many column="MasterItemCode" > class="emPowerBO.MasterItem,emPowerBO" outer-join="true"/> > </bag> > > Now remove child working fine, but if i insert New MasterItem to my > existing MasterItemList, in backend its re-creating all existing rows > of the MasterItemList with new ID for particular parent > (MasterCategory) > > am i clear ? > > On Apr 6, 7:19 pm, James Crowley <[email protected]> wrote: > > > > > cascade to all will remove them all, only if you delete the root entity. > > > if you want the collection items to be removed, while the root entity > > remains, it needs to be all-delete-orphans. > > > hope that helps > > > 2009/4/6 Vels <[email protected]> > > > > i changed cascade="all" ... but still same problem > > > > <bag name="MasterItemList" table="tblCategorisedItems" > > > cascade="all" > > > collection-type="Collection.ObservableList`1 > > > [[emPowerBO.MasterItem, emPowerBO]], Collection"> > > > <key column="CategoryCode"/> > > > <many-to-many column="MasterItemCode" > > > class="emPowerBO.MasterItem,emPowerBO"/> > > > </bag> > > > > On Apr 6, 5:19 pm, James Crowley <[email protected]> wrote: > > > > You might want to check your cascade options? If you want orphaned > > > entities > > > > to be removed, you need to set it to all-delete-orphans... but make sure > > > you > > > > understand the implcations of this. > > > > > Seehttp:// > > > ayende.com/Blog/archive/2006/12/02/NHibernateCascadesTheDiffer... > > > > more info. > > > > > Hope that helps > > > > > James > > > > > 2009/4/6 Vels <[email protected]> > > > > > > Hi... > > > > > > I am working with VB.Net 2008, SQL 2005, NH2.0.1 > > > > > > followings are my mapping information: > > > > > > <?xml version="1.0" encoding="utf-8" ?> > > > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" > > > > > namespace="emPowerBO" assembly="emPowerBO" > > > > > schema="emPowerMasterV4.dbo"> > > > > > <class name="MasterCategory" proxy="MasterCategory" > > > > > table="tblCategories" lazy="true" > > > > > discriminator-value="MasterCategory"> > > > > > <id name="CategoryCode" column="CategoryCode" type="Int64" unsaved- > > > > > value="0"> > > > > > <generator class="native"/> > > > > > </id> > > > > > <property column="CategoryName" type="string" name="CategoryName" > > > > > not-null="true" length="255"/> > > > > > > <bag name="MasterItemList" table="tblCategorisedItems" > > > > > cascade="none" > > > > > collection-type="Collection.ObservableList`1 > > > > > [[emPowerBO.MasterItem, emPowerBO]], Collection"> > > > > > <key column="CategoryCode"/> > > > > > <many-to-many column="MasterItemCode" > > > > > class="emPowerBO.MasterItem,emPowerBO"/> > > > > > </bag> > > > > > > </class> > > > > > </hibernate-mapping> > > > > > > test 1 :MasterItemList.add(Masteritem1) > > > > > :session.update(MasterCategory) > > > > > :trans.Commit() > > > > > works fine :) Masteritem1 added to my collection and table > > > > > too > > > > > > test 2 :MasterItemList.add(Masteritem2) > > > > > :session.update(MasterCategory) > > > > > :trans.Commit() > > > > > :Masteritem2 added to my collection and table too > > > > > > :MasterItemList.Remove(Masteritem1) > > > > > :session.update(MasterCategory) > > > > > :trans.Commit() > > > > > :Masteritem1 removed from my collection but not deleted from > > > > > my table > > > > > > test 3 :MasterItemList.remove(Masteritem1) > > > > > :session.update(MasterCategory) > > > > > :trans.Commit() > > > > > : works fine :) Masteritem1 removed from my collection and > > > > > from table too > > > > > > :MasterItemList.Remove(Masteritem2) > > > > > :session.update(MasterCategory) > > > > > :trans.Commit() > > > > > :not working :( Masteritem2 removed from my collection but > > > > > not from table > > > > > > what could be the mistake ? > > > > > is my mapping informations correct ?- Hide quoted text - > > > > > - Show quoted text - > > > -- > > James Crowley > > Managing Director > > Developer Fusion - Connecting developers worldwide > > > Developer Fusion Ltd | 58 Sandringham Close | Enfield, EN1 3JH > > mob: 07986 624128 web:http://www.developerfusion.com/-Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
