-->
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: Suppression de la relation parente en ManyToMany
PostPosted: Fri Jun 24, 2011 5:36 am 
Newbie

Joined: Fri Jun 24, 2011 5:09 am
Posts: 2
Bonjour,

Dans une relation ManyToMany, Je n'arrive pas à supprimer la relation parente à partir de la classe fille, voici ma configuration :

public classe Parente{
@ManyToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
@JoinTable(name = "parent_has_child", joinColumns = { @JoinColumn(name = "parent_id") }, inverseJoinColumns = { @JoinColumn(name = "child_id") })
public Collection<Child> ChildList = new ArrayList<Child>();
}

public class Child{
@ManyToMany(mappedBy = "ChildList", cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
public Collection<Parent> ParentList = new ArrayList<Parent>();
}

Donc à partir d'un objet Child j'effectue les associations suivantes (les membres sont en public pour faciliter l'exemple)

// Création de la liste des parents sachant que les parents existent déjà en base de données
Collection<Parent> rParentList = new ArrayList<Parent>();
ParentList.add(new Parent(parent1));
ParentList.add(new Parent(parent2));
ParentList.add(new Parent(parent3));

// Association avec l'objet fils qui existe lui aussi en base de données
Child rChild = new Child();
rChild.ParentList = rParentList;

getSession().saveOrUpdate(rChild);

Malgré le code ci-dessus, les associations dans la table d'association ne sont pas crées. Pouvez-vous me dire quelle est l'erreur ?

Merci d'avance,


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.