-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping many-to-many associations with a map
PostPosted: Tue Sep 28, 2010 3:42 am 
Newbie

Joined: Wed Sep 12, 2007 1:58 pm
Posts: 12
Hi,

I have a many-to-many association which I'd like to map using a Map. To follow the example in the JPwH book, assume I have Category, Item, and CategorizedItem tables and entities. The category_item table is a join table with a PFK to category_id and item_id, and has additional columns. CategorizedItem can be a value type component in my case.

Is it possible to map the Category entity such that it has a map of CategorizedItems keyed by Item, i.e.

Code:
Map<Item, CategorizedItem> categorizedItems = new HashMap<Item, CategorizedItem>()


In JPwH pp. 312, a third table is used for this, but I'm not sure it can be done on a simple many-to-many association.

This seems like quite a natural and powerful mapping to me. If I'm holding a Category entity, I can immediately retrieve a CategorizedItem by Item with categorizedItems.get(item), or check if an Item has been categorized with categorizedItems.containsKey(item).

Thanks,
Emerson


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

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.