-->
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: Help with complex relationship
PostPosted: Thu Oct 13, 2005 3:52 pm 
Beginner
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 3:59 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
have you mapped both properties w/ many-to-one ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 9:24 am 
Beginner
Beginner

Joined: Mon Dec 08, 2003 12:15 am
Posts: 47
That probably would work, but I was wondering if anybody had any ideas as to how to better model this situation.

Thanks for your reply though and I will give it a try.


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.