I have a class User. A user can be a friend with many other users. The relationship is mutual. If A is a friend of B then B is a friend of A. Also I want every relation to s
I'm not sure this will fit your case, but give it a try.
@Entity
public class Friend {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int friendId;
@Column
private String name;
@ManyToMany(mappedBy="owner")
private List friendships;
}
@Entity
public class Friendship {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int friendshipId;
@OneToOne
private Friend owner;
@OneToOne
private Friend target;
// other info
}