-->
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: problem with may to many association
PostPosted: Fri Oct 20, 2006 12:58 pm 
Newbie

Joined: Thu Oct 05, 2006 11:34 am
Posts: 8
I have two entity POJOs Student and Course and they are associated with many to many associatoin.

The association was created using the code snippet shown below:

@ManyToMany(targetEntity=Course.class,cascade=CascadeType.ALL)
@JoinTable(name="student_course_map",
joinColumns=@JoinColumn(name="student_id"),
inverseJoinColumns=@JoinColumn(name="course_id")
)
public Collection getCourses()
{
return _courses;
}


@ManyToMany(targetEntity=Student.class,cascade=CascadeType.ALL)
@JoinTable(name="student_course_map",

joinColumns=@JoinColumn(name="course_id"),
inverseJoinColumns=@JoinColumn(name="student_id")
)
public Collection<Student> get_student() {
return _student;
}

The problem is when i delete any student, deletion is done on its corresponding student table as well as association table but deletion is done in course table also i.e corresponding course object is also deleted from the table. But i want the deletion from the student table and association table only.

How can i do that?

_________________
.::hIBERNATe rOCKs::.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 4:35 pm 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
If you don't want the course element to be deleted upon the deletion of a student you have the wrong cascade in your mapping:

Try this one instead:

Code:
cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}

_________________
Please don't forget to rate


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.