dev@glassfish.java.net

Re: Delete the ManyToMany relationship...

From: Dyego Souza Dantas Leal <dyego.leal_at_gmail.com>
Date: Mon, 10 Jul 2006 16:34:44 -0300

OK , but habve no BULK command for this operation ? I need to retrive
the Entity from database and call .removeallGroups() or exists a
em.createQuery("delete from...") to this operation ?




Craig L Russell escreveu:
> 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!
>


-- 
-------------------------------------------------------------------------
++  Dyego Souza Dantas Leal   ++           Dep. Desenvolvimento   -------------------------------------------------------------------------
               E S C R I B A   I N F O R M A T I C A
        ***        http://javacoffe.blogspot.com        ***
-------------------------------------------------------------------------
The only stupid question is the unasked one (somewhere in Linux's HowTo)
Linux registred user : #230601
--                                        ICQ   : 1647350
$ look into "my eyes"                     Phone : +55 041 2106-1212    
look: cannot open my eyes                 Fax   : +55 041 3296-6640     -------------------------------------------------------------------------
             Reply: dyego_at_escriba.com.br