jjczopek
jjczopek

Reputation: 3379

Play! - Many to many relationship on same model class

I have a simple model class in my Play! application:

@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;

}

How to properly annotate and/or modify this class to be able to fetch users that current user is following and fetch users that are following current user?

Upvotes: 1

Views: 473

Answers (1)

Andr&#233; Pareis
Andr&#233; Pareis

Reputation: 1094

Should be as simple as:

@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;
}

Upvotes: 3

Related Questions