-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: possible to delete just the relationship on a many-to-many?
PostPosted: Sat May 23, 2009 2:15 pm 
Newbie

Joined: Fri May 22, 2009 2:49 pm
Posts: 2
I have

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Entity.Alex">
<class name="Entity.Alex.Asset.BookAsset" table="asset_asset_type_book">

<id name="ID">
<column name="asset_id" sql-type="int" not-null="true"/>
<generator class="identity" />
</id>

<property name="Plot" column="plot" type="String" not-null="true" />

...snip...

<set name="Castings" inverse="true" table="asset_asset_people_link" where="asset_person_type_ref=2" cascade="all">
<key column="asset_id"/>
<many-to-many class="Entity.Alex.AssetMeta.Casting" column="people_id" />
</set>


</class>

</hibernate-mapping>

and

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Entity.Alex">

<class name="Entity.Alex.AssetMeta.Casting" table="asset_people">
<id name="ID">
<column name="people_id" sql-type="int" not-null="true"/>
<generator class="identity" />
</id>

<set name="Parents" table="asset_asset_people_link" inverse="false" cascade="all">
<key column="people_id"/>
<many-to-many class="Entity.Alex.Asset.BookAsset" column="asset_id" />
</set>

<property name="Name" column="name"/>



</class>

</hibernate-mapping>

What code would delete just the relationship. I am trying various combinations of:

Entity.Alex.Asset.BookAsset ent = 'the Book Asset Entity';

for (int i = ent.Castings.Count - 1; i >= 0; i--)
{
Entity.Alex.AssetMeta.Casting t = ent.Castings.ElementAt<Entity.Alex.AssetMeta.Casting>(i);
if (t.State == KPU.Application.Contracts.Data.linked_entity_state.delete_link_or_child)
{
ent.Castings.Remove(t);
//t.Parents = null;
//session.Delete(t);
}
}

NOTE: The property t.State is set in the client to signal that the relationship can be deleted.

Thanks.


Top
 Profile  
 
 Post subject: Re: possible to delete just the relationship on a many-to-many?
PostPosted: Wed May 27, 2009 5:07 am 
Beginner
Beginner

Joined: Fri Jun 01, 2007 4:55 pm
Posts: 24
You are looping through a collection and amending the collection as you go. Surely this will end up in some kind of error (out of bounds or something)

You have said inverse = false to the "Entity.Alex.AssetMeta.Casting" class, but you're removing the items from the other side of the relationship. Remove them from the casting class and NHibernate should then update.

I believe the reason nothing is happening, is because the inverse=true on the BookAsset means "I don't need to update, as i delegate responsibility to the other side"

Hope that helps


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.