12

想到这个,我的大脑开始受伤,是不是很简单:

@ManyToMany(mappedBy = "following", cascade = CascadeType.ALL)
private Set<User> followers = new HashSet<User>();

@ManyToMany(mappedBy = "followers", cascade = CascadeType.ALL)
private Set<User> following = new HashSet<User>();
4

1 回答 1

12

就像是:

@ManyToMany(mappedBy = "following", cascade = CascadeType.ALL)
@JoinTable(name="UserRel", 
                joinColumns={@JoinColumn(name="ParentId")}, 
                inverseJoinColumns={@JoinColumn(name="UserId")})
private Set<User> followers = new HashSet<User>();

@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name="UserRel", 
                joinColumns={@JoinColumn(name="UserId")}, 
                inverseJoinColumns={@JoinColumn(name="ParentId")})
private Set<User> following = new HashSet<User>();
于 2012-12-04T17:24:14.190 回答