Hi, I guess it's probably a common issue, but even after searching the forum, I don't find the answer
I have an entity User, which contains 2 List<User>
One list is Friends, the other Family.
Obviously this is a many to many relationship (one guy may have several friends or family, and one of his friend can have other User friend)
I can not manage to do the correct mapping
I have now
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "user")
@JoinTable(name = "FRIENDS")
public List<User> getFriends() {
return charms;
}
How should I do the mapping, knowing I want it to be BIDIRECTIONAL, because then I can find the Friends of a User, but I also want to be able to know of which Users I am Friend
Thanks for any help!
Here is my full class:
Quote:
@Entity
@Table(name = "USERS")
public class User implements Serializable {
private Long id;
private String username;
private List<User> Friends = new ArrayList<User>();
private List<User> Family = new ArrayList<User>();
@Id
@GeneratedValue
@Column(name = "ID", nullable = false)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "USERNAME", nullable = false)
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "user")
@JoinTable(name = "FRIENDS")
public List<User> getFriends() {
return friends;
}
public void setFriends(List<User> friends) {
this.friends = friends;
}
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "user")
@JoinTable(name = "FAMILY")
public List<User> getFamily() {
return family;
}
public void setFamily(List<User> family) {
this.family = family;
}
}