Help us understand the problem. What is going on with this article?

Play Framework 2.4 java ebean関連モデルのJson化

More than 3 years have passed since last update.

Play Framework 2.4で関連したモデルをJsonにするとこでハマったのでメモ


OneToManyのモデルをtoJson()したらthrough reference chainというエラー。




    public Result test() {
        return ok(Json.toJson(User.find.byId(1L)));
@Entity @Table(name = "users")
public class User extends Model {

    public Long id;

    public String name;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    public List<Memo> memos;

    public static final Find<Long, User> find = new Find<Long, User>(){};
@Entity @Table(name = "memos")
public class Memo extends Model {

    public Long id;

    public String name;

    public String memo;

    @JoinColumn(name = "user_id")
    public User user;
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away