-->
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.  [ 5 posts ] 
Author Message
 Post subject: ternary association mapping
PostPosted: Mon Jan 02, 2006 2:45 pm 
Newbie

Joined: Wed Dec 21, 2005 12:19 pm
Posts: 4
Hi. I'm having problems mapping a ternary association. I have 3 classes: Product, Notification and Subscriber. For a given Product and Subscriber, I want a list (or better, a set) of Subscribers. I thought of modeling this as a <map> in Product as following:

Code:
<class name="IProduct" table="Product" lazy="true">
(snip...)
<map name="notifications" table="NotificationSubscription" lazy="true" inverse="false">
  <key column="producto"/>
  <index-many-to-many class="ISubscriber" column="subscriber"/>
  <many-to-many class="INotification" column="notification"/>
</map>
</class>


but it seems this mapping is only good for getting one Subscriber (given the Product and the Subscriber, which is the key of the map)

So, how do I model this association? I'd really really like to use <map> since it's much easier than sets of composite-elements or things like that...

Of course I have ISubscriber and INotification correctly mapped.

I'm using NHibernate 1.0.1.0 with MSSQL 2000

TIA

Mauro


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 2:56 pm 
Newbie

Joined: Wed Dec 21, 2005 12:19 pm
Posts: 4
Oops! Correction:
For a given Product and Subscriber, I want a list (or better, a set) of Notifications


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 3:16 pm 
Newbie

Joined: Wed Dec 21, 2005 12:19 pm
Posts: 4
hmmm... many people had the same problem and none got it solved:

http://forum.hibernate.org/viewtopic.php?t=933592
http://forum.hibernate.org/viewtopic.php?t=932376
http://forum.hibernate.org/viewtopic.php?t=929036

any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 3:42 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
mauricitoia wrote:
Oops! Correction:
For a given Product and Subscriber, I want a list (or better, a set) of Notifications


The problem seems to be one with the Hibernate docs, which make no distinction between the "type" of ternary relationship modelled by each suggested form of mapping. Using a map with an index-many-to-many is a "limited" ternary relationship: given element-types A, B and C, there will be one and only one C for each A-B pair. If you need an "open" ternary relationship, you'll have to use the composite-element mapping (see the last code example in this section).

However, it appears that what you really want is a map (hashtable, keyed on Subscriber) of sets of Notifications. I may be wrong, but I don't think there is any way to natively map this in NHibernate. You may still be able to provide the desired semantics in your business objects, however, while maintaining the necessary structures for persistence behinds the scenes.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 1:18 pm 
Newbie

Joined: Wed Dec 21, 2005 12:19 pm
Posts: 4
Thanks, that's what I meant, a map of sets. What I did was map the relation as a set and then wrap the set with a class implementing IDictionary. It sucks for queries, since it's O(n), but it works...

_________________
Mauro


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.