-->
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.  [ 4 posts ] 
Author Message
 Post subject: add / remove in a Many-to-Many composited List
PostPosted: Thu Oct 30, 2003 11:48 am 
Newbie

Joined: Mon Sep 08, 2003 3:04 pm
Posts: 12
Hello,
When I have a mapping like (class Forfait):
Quote:
<set
role="services"
table="tbl_liens_forfaits_services"
>
<key column="forfait_id"/>
<many-to-many
class="Service"
column="service_id"
/>
</set>


then it's easy to add / remove elements in the set:
forfait.getServices().add(service)
forfait.getServices().remove(service)


Now if I have to put some information on the association,
then I use composite-element :

Quote:
<set
role="services"
table="tbl_liens_forfaits_services"
>
<key column="forfait_id"/>
<composite-element class="RelationForfaitService">
<property name="precision" type="string"/>
<many-to-one name="service" column="service_id" class="Service"/>
</composite-element>
</set>


Then what is the smartest way to code when I have to add & remove
elements from the Set?

Thanks
--
Franck


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2003 12:24 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 7:53 pm
Posts: 66
Location: Lakeland, Florida USA
Quote:
what is the smartest way to code when I have to add & remove
elements from the Set?

Code:
forfait.getServices().add(relationForfaitService)
forfait.getServices().remove(relationForfaitService)


The downside of using composite here is that its not an entity and therefore will not receive interceptor callbacks. Of course, you could easily handle that in forfait.

The other option is, of course, to use an entity here but that would require a composite index. So, which is worse, no callbacks or dealing with an composite index?

Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2003 2:34 pm 
Newbie

Joined: Mon Sep 08, 2003 3:04 pm
Posts: 12
Well,

I think I don't understand something with many-to-many
'composited' Collection.

Actually I really don't see the interest to map a set by :

<set
role="services"
table="tbl_liens_forfaits_services"
>
<key column="forfait_id"/>
<composite-element class="RelationForfaitService">
<property name="precision" type="string"/>
<many-to-one name="service" column="service_id" class="Service"/>
</composite-element>
</set>


against a one-to-many

<set role="services" table="tbl_liens_forfaits_services">
<key column="service_id"/>
<one-to-many class="RelationForfaitService"/>
</set>


The 2 solutions give the same result :
a Set of RelationForfaitService.class instances

With the one-to-many, I have to do a mapping file for
the RelationForfaitService Class

But is-it the only disadvantage of the second solution?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2003 2:41 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 7:53 pm
Posts: 66
Location: Lakeland, Florida USA
Quote:
The 2 solutions give the same result :
a Set of RelationForfaitService.class instances


Right. Beside the additional mapping file, the entity solution (2nd) typically will require a composit Id class, but it doesn't have to. What is the primate key of RelationForfaitService? Isn't it a composit key? With the 1st solution, you don't need this.

Jeff


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

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.