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