-->
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: ManyToMany from the same table?
PostPosted: Tue Mar 30, 2010 6:00 pm 
Newbie

Joined: Tue Mar 30, 2010 2:10 pm
Posts: 4
Perhaps this question has been asked before, however I was unable to find an answer in the forum.

The problem is the following:

I have a class that says the folowing

Code:
public class User {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "ID")
private Integer id;
@ManyToMany
List<Users> friends;
@ManyToMany
List<Users> friendsRequests;
...


How do I specify that the friends are saved in the FRIENDS table, and the friendsRequests are saved in the FRIENDSREQUESTS table?

Given the current code, hibernate creates USERS_USERS table which does not distinguish the FRIENDS from the FRIENDSREQUESTS....

Thanks in advance...

Vasko


Top
 Profile  
 
 Post subject: Re: ManyToMany from the same table?
PostPosted: Wed Mar 31, 2010 7:44 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
hi, did you try this?

Code:
@ManyToMany
@JoinTable(name = "user_to_friendsusers")
List<Users> friends;
@ManyToMany
@JoinTable(name = "user_to_friendsrequest")
List<Users> friendsRequests;

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: ManyToMany from the same table?
PostPosted: Wed Mar 31, 2010 10:03 am 
Newbie

Joined: Tue Mar 30, 2010 2:10 pm
Posts: 4
Yes, I did try that and it did not work.. However, it was my mistake because I did not drop the original Users table, so Hibernate tried just an update, regarding it as its an default operation in my persistence.xml... After I dropped the Users table it worked like a charm... :)

Thanks anyway for the reply...


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.