-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to emulate a quirky many-to-many join structure
PostPosted: Wed Nov 07, 2007 3:10 am 
Newbie

Joined: Wed Nov 07, 2007 3:00 am
Posts: 2
Hi,

I'm a bit stuck and would appreciate a pointer in the right direction. I have a particular table setup and I'm having trouble trying to work out how to emulate it in nhibernate.

The structure is basically a many-to-many relationship with some quirks. There is a table RssItem which has an id, title and a description. There is another table called Phrase which has an id and a phrase string.

Then there is the join table. The join table has 4 fields:
- RssItemId
- PhraseId
- NumberOfOccurrences
- TitleOrDescription

NumberOfOccurrences specifies how many times the phrase occurs in the rss item and TitleOrDescription specifies whether this join relates to the title field or the description field.

Because I'm used to thinking about a problem like this outside of an ORM tool, I'm not quite sure how I structure my nhibernate mappings so that I can effectively perform queries along the lines of:

- how many times was phrase X found in any description across all rss items?
- how many occurrences of phrase Y were in the title of RssItem K?
- which RssItems contained phrase X more than once in the description?

etc. You get the picture. Anyway, any advice would be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 07, 2007 8:43 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
You have two choices here.

One you could use a one-to-many relationship from both RssItem and Phrase and then Many-to-one relationships from this join entity back to the RssItem and Phrase. I personally like this approach the best.

Second you could look at the composite-element mapping (see the NHibernate docs for more information on this one). The composite element basically lets you treat the relationship like a many to many with value type semantics in the middle.

Honestly, forget I even mentioned the composite-element and just use the One-to-many and many-to-one relationship. Just remember to set inverse="true" on the one-to-many side.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 07, 2007 8:31 pm 
Newbie

Joined: Wed Nov 07, 2007 3:00 am
Posts: 2
Thanks for the help, I'll give it a go.


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