dev@glassfish.java.net

Re: Delete the ManyToMany relationship...

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Mon, 10 Jul 2006 13:22:47 -0700

Hi Dyego,

Bulk delete is intended for removing entities. You can try
bulk update, but the cached entities (if you have any that
are affected by such operation) will still have their
relationships as before the updates (at least with GlassFish
implementation, and it's permitted by the spec), so you'll
need to call refresh on the entities (one by one - there is
no Collection based refresh) from both sides of the relationship
before the change. Which means that you won't save much
in this particular case.

regards,
-marina

Dyego Souza Dantas Leal wrote On 07/10/06 12:34,:
> 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!
>>
>
>
>