玩! - 同一模特班上的多对多关系

时间:2011-05-30 13:17:22

标签: hibernate jpa playframework

我的Play中有一个简单的模型类!应用程序:

@Entity
public class User extends Model {

    public String login;
    public String password;
    public String fullName;
    public Date lastLogin;


    public List<User> following;

    public List<User> followedBy;

}

如何正确地注释和/或修改此类,以便能够获取当前用户正在关注的用户并获取跟随当前用户的用户?

1 个答案:

答案 0 :(得分:3)

应该如此简单:

@Entity
public class User extends Model {

    public String login;
    public String password;
    public String fullName;
    public Date lastLogin;

    @ManyToMany(mappedBy = "followedBy") public List<User> following;
    @ManyToMany public List<User> followedBy;
}