dev@glassfish.java.net

RE: Delete the ManyToMany relationship...

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Mon, 10 Jul 2006 11:02:35 -0400

Hello,
  The best way to delete the User and have the relation table updated is to call em.remove(userToDelete). TopLink will automatically remove any references for the User from the relation table. You can also use a bulk delete (ie Delete from User where...) and TopLink will automatically update the relation table.
--Gordon

-----Original Message-----
From: Dyego Souza Dantas Leal [mailto:dyego.leal_at_gmail.com]
Sent: Monday, July 10, 2006 7:55 AM
To: dev_at_glassfish.dev.java.net
Subject: Delete the ManyToMany relationship...


I'm have this entity mapping:


Class User ( the 'user' table )
Class Group ( the 'group' table )
and the 'user_group' is a joining table with this relationship:


on User class:

@ManyToMany(fetch=FetchType.EAGER,mappedBy = "ugUser")
private java.util.Set <Group> ugGroup = new HashSet<Group>();

on Group class:

@JoinTable(name = "user_group", joinColumns = {_at_JoinColumn(name =
"ug_group", referencedColumnName = "gr_id")}, inverseJoinColumns =
{_at_JoinColumn(name = "ug_user", referencedColumnName = "us_id")})
@ManyToMany(fetch=FetchType.EAGER)
private java.util.Set <User> ugUser = new HashSet<User>();



Ok , at here... nothing new...


One user have MANY GROUPS
One group have Many USERS !!!


OK... but... if the user has 3 groups... what is EJB-QL to delete the
relations for ONE USER ?

ex: User 1 have three groups on relation table (user_group) , what is
EJB-QL to delete groups on user_group ?


Tnks ! this is very important to me...


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: dev-help_at_glassfish.dev.java.net