Beginner |
|
Joined: Mon Dec 08, 2003 12:15 am Posts: 47
|
Hibernate version: 3.0
Please forgive the fact that there are no mapping documents or code since this is a project that is starting up and Hibernate is my tool of choice for this task.
I have in my hands a strange mapping that I need to model in an application that is just ramping up.
The relationship I am trying to model is as follows:
A team can play many matches, and a match can be played by at most two teams in this case. The relational model I am leaning towards is that of a Team table (one side of relation) and a Match table (many side of relation).
So what I am leaning towards is having a collection in my Team class:
public class Team{
private Set matches;
...
}
In my match class I need the following;
public class Match{
private Team team; //
private Team opponent; //opponent of team which is essentially a Team in the team table
//other fields here...
}
As you can see I have two objects of the same type in the Match class. They each will need to refer back to the Team's team_id column in the Team table.
I know I can get my first team in the Match class mapped back to its corresponding record in the Team table through a many-to-one, but how do I get hibernate to also retrieve the corresponding Team for the opponent field in the Match class.
Thanks in advance to anyone who can give me some pointers on this.
|
|