dev@glassfish.java.net

Re: Delete the ManyToMany relationship...

From: Craig L Russell <Craig.Russell_at_Sun.COM>
Date: Mon, 10 Jul 2006 12:24:41 -0700

Hi Dyego,

If you want to remove just the relationships for one user with all
its groups without removing the user or the groups, the portable way
is to iterate the list of groups and remove the relationship from
both sides, as:

class User {
...
   removeAllGroups() {
     for (Group g: ugGroup) {
       g.ugUser.remove(this);
     }
     ugGroup.removeAll();
   }
}

Craig

On Jul 10, 2006, at 4:54 AM, Dyego Souza Dantas Leal wrote:

> 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
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell_at_sun.com
P.S. A good JDO? O, Gasp!