-->
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.  [ 1 post ] 
Author Message
 Post subject: using Cascade on ManyToMany associations
PostPosted: Fri Jun 27, 2008 7:03 am 
Newbie

Joined: Tue Jun 17, 2008 1:44 pm
Posts: 3
Hi,

I use hibernate 3.3.0ga.

Let's say we have a simple Person Entity which could have several employers and severals employees. There would be an ManyToMany association like :

Code:
    @Entity
    public class Person {
    ...
      @ManyToMany
      @JoinTable(name = "employers_employees")
      public List<Person> getEmployees() {
          return employees;
      }
     
     @ManyToMany(mappedBy = "employees")
     public List<Person> getEmployers(){
        return employers;
     }


In the database, a special join table, "employers_employees", will be created with 2 columns, say :
- employee_id
- employer_id

If I delete a Person , how can I cascade my relationship @ManyToMany to delete only the related entries in the join table "employers_employees" but not the associated persons (employers and employees)

As far as I tested, this is not the default behaviour : when I try to delete a Person, hibernate says it will be resaved by cascade because some other object contains it in its collection.

Is there a way to map ManyToMany collections for me not to care about those problems ?

Thanks


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

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.