-->
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.  [ 4 posts ] 
Author Message
 Post subject: delete one-to-many
PostPosted: Wed Jul 13, 2005 6:33 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 5:07 am
Posts: 33
I have class Feature and Class CPProfile. they have many to many relationship. I use to one-to-many and CPProfile_Feature class since it has another column. When I try to delete the child (CPProfile_Feature ) the parent (Feature) is being deleted as well!! Why?
I do: Feature f = session.load(....)
f.deleteFeaturesFromProfiles();

Here are my classes:
Class Feature{

Set featuresProfiles = new HashSet();
/**
* @hibernate.set
* cascade="save-update"
* inverse="false"
* lazy="true"
*
* @hibernate.collection-key
* column="FEATURE_ID"
*
* @hibernate.collection-one-to-many
* class="CPProfile_Feature"
*
*
* @return Returns the featuresProfiles.
*/
public Set getFeaturesProfiles() {
return featuresProfiles;
}


public void deleteFeaturesFromProfiles(){
Set profileFeatures = featuresProfiles;
for (Iterator it2 = profileFeatures.iterator(); it2.hasNext();)
{
CPProfile_Feature theProfileFeatures = (CPProfile_Feature)it2.next();
CPProfile theProfile = theProfileFeatures.getProfile();
theProfile.getFeaturesProfiles().remove(theProfileFeatures);
}
profileFeatures.clear();
}
}




Class CPProfile{

Set featuresProfiles = new HashSet();

/**
* @hibernate.set
* cascade="save-update"
* inverse="false"
* lazy="true"
*
*
* @hibernate.collection-key
* column="CPPROFILE_ID"

* @hibernate.collection-one-to-many
* class="CPProfile_Feature"
*
*
* @return Returns the featuresProfiles.
*/
public Set getFeaturesProfiles() {
return featuresProfiles;
}

}


Class CPProfile_Feature{

private CPProfile profile;
private Feature feature;

/**
* @hibernate.many-to-one
* name="category"
* insert="true"
* update="true"
* not-null="true"
* column="CPPROFILE_ID"
*
* @return Returns the profile.
*/
public CPProfile getProfile() {
return profile;
}

/**
* @hibernate.many-to-one
* name="feature"
* insert="true"
* update="true"
* not-null="true"
* column="FEATURE_ID"

* @return Returns the feature.
*/
public Feature getFeature() {
return feature;
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 13, 2005 12:52 pm 
Beginner
Beginner

Joined: Fri Jul 08, 2005 12:38 pm
Posts: 41
Location: Massachusetts, USA
I think you want inverse="true" on your parent object.


Top
 Profile  
 
 Post subject: Inverse="true"
PostPosted: Fri Jul 15, 2005 2:09 am 
Newbie

Joined: Fri Jul 15, 2005 12:42 am
Posts: 18
Inverse="true" true must work for delete but inserting new Parent along with new children will cause problems parent ID is entered as 0 !! At least its causing me that!!
Please Comment


Top
 Profile  
 
 Post subject: Re: Inverse="true"
PostPosted: Fri Jul 15, 2005 2:37 am 
Newbie

Joined: Fri Jul 15, 2005 12:42 am
Posts: 18
dilipr wrote:
Inverse="true" true must work for delete but inserting new Parent along with new children will cause problems parent ID is entered as 0 !! At least its causing me that!!
Please Comment

I have explained this prob in my own Post
http://forum.hibernate.org/viewtopic.php?t=945092


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.