@Entity
public class Argument extends Model
{
@Id
public Long id;
@Required @NotEmpty @Size(max = 140)
public String summary;
@SuppressWarnings("unchecked")
public static Finder<Long, Argument> find = new Finder(Long.class, Argument.class);
...
}
和
@Entity
public class Relation extends Model
{
@Id
public Long id;
@Required @ManyToOne @NotNull @JsonManagedReference
public Argument from;
@ManyToOne @JsonManagedReference
public Argument toArgument;
@ManyToOne @JsonManagedReference
public Relation toRelation;
@Required @NotNull
public Integer type;
...
}
基本上,Relation
連接兩個參數(或參數和其他關係)在一起。這是兩個類之間的單向關係。然而,我得到
[RuntimeException: java.lang.IllegalArgumentException: Infinite recursion
(StackOverflowError) (through reference chain: models.Argument["relations"]->
com.avaje.ebean.common.BeanList[0]->models.Relation["from"]->
models.Argument["relations"]-> ... ->models.Argument["relations"])
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:611) ~[jackson-databind.jar:2.2.2]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:142) ~[jackson-databind.jar:2.2.2]
...
當我嘗試做
find.where().or(Expr.eq("from", argument), Expr.eq("toArgument", argument)).findList();
,過一會兒給該結果Json.toJson
。
將@JsonBackReference
添加到引用Argument
的字段通過完全忽略這些字段來解決問題,這不是我想要的。加入@JsonManagedReference
可以使問題保持不變,因爲我沒有看到任何地方添加@JsonBackReference
- 這是一個單向關係,可以幫助您!
基本上,我想要的只是涉及某個參數的JSON數組關係。代表關係的JSON對象應該只包含ID - 像{id: 1, from: 4, toArgument: 3, type: 1}
就是我想要的東西。
編輯我要補充的是先前與Argument
模式運行良好的觀點現在遇到了同樣的錯誤時,該請求是JSON - 儘管工作僅與參數!爲什麼當一個完全不同的類中的某些東西影響了參數時,我根本就沒有改變參數?