Hi guys,
this is my first post on the forum so please forgive me if my question has already been answered. I've searched the forums, online doco etc, and still can't find a solution for what I'm trying to do.
I'm using hibernate 2.1, with mySql 4.01 and java1.4.2_08
I want to create a many-to-many mapping from a class to itself.
For example, I have a User class who submits documents for review. A User can both be a reviewer and a reviewee. So I would have something like the following:
Code:
public class User
{
Set reviewers;
Set reviewees;
/* when I add a reviewer, I must become a reviewee for this user */
public void addReviewer(User rr)
{
rr.addReviewee(this);
reviewers.add(rr);
}
/* when I add a reviewee, I must become a reviewer for them */
public void addReviewee(User re)
{
re.addReviewer(this);
reviewees.add(re);
}
/* return a set of users who reviewed my document */
Set getReviewers() { return reviewers; }
/* get a list of users who's documents I reviewed */
Set getReviewees() { return reviewees; }
}
I can't get mapping correct:
Code:
<class name="user" class="User" table="USER">
<set role="reviewers" table="USER_REVIEWS">
<key column="reviewer_id"/>
<many-to-many column="reviewee_id" class="User"/>
</set>
<set role="reviewees" table="USER_REVIEWS">
<key column="reviewee_id"/>
<many-to-many columm="reviewer_id" class="User"/>
</set>
</class>
I'd expect to have two table in my database, USER table and a USER_REVIEWS table. The second table I'd expect to contain two columns, a reviewer_id and a reviewee_id that are both foreign keys back to the user table, with both columns making up the primary key.
I'd appreciate any help, even if its just a RTFM pointed at the right place ;-)
Thanks.
dbrady.