I am relatively new to Hibernate, and need some help writing the mapping file for my database.
Consider the following classes:
Code:
--------------------------------- ------------------ ------------------
| ClassA | ClassB | ClassC
--------------------------------- ------------------ ------------------
| | |
| id : int | id : int | id : int
| name : String | name : String | name : String
| abMap : Map<ClassB, Set<ClassC>> | |
| | |
ClassB and ClassC are simple, and ClassA has a Map. This map takes a set of ClassB's, and for each, maps a set of ClassC's.
Now consider the following table structure:
Code:
------------------ ------------------ ------------------
| TableA | LinkAB | TableB
------------------ ------------------ ------------------
| | |
| id : int | id : int | id : int
| name : String | tableA_id : int | name : String
| | tableB_id : int |
| | |
This is a fairly straightforward many-to-many relationship.
Here's where it gets complicated. Consider the following additional tables:
Code:
------------------ ------------------ ------------------
| LinkAB | LinkCAB | TableC
------------------ ------------------ ------------------
| | |
| id : int | id : int | id : int
| tableA_id : int | linkAB_id : int | name : String
| tableB_id : int | tableC_id : int |
| | |
Now, in addition to the earlier many-to-many, I also have a new many-to-many linking TableC with LinkAB.
How can I represent this in Hibernate config? I'm stuck!
It's almost as though I want some kind of <map><set>...</set></map> structure, but I can't figure it out.
Any help would be GREATLY appreciated. If anyone knows what kind of relationship this is officially termed, that would be helpful too. I'm guessing it's not a "many-to-many-to-many".