我的大脑开始思考这个问题,它是否如此简单:
@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>();
答案 0 :(得分:8)
类似的东西:
@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>();