【发布时间】:2017-08-29 09:31:51
【问题描述】:
我在一个类中有多个反向引用类。因为我为他们使用@JsonBackReference,所以我得到一个错误。我为这些类分配了@JsonIdentityInfo 注释,但我仍然得到同样的错误。
public class X implements Serializable {
....
//bi-directional many-to-one association to Booking
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "xxA", nullable = false)
@JsonBackReference
private A a;
//bi-directional many-to-one association to Client
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "xxB", nullable = false)
@JsonBackReference
private B b;
...getters setters
}
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
public class B implements Serializable {
........
//bi-directional many-to-one association to BookedClient
@OneToMany(mappedBy = "b", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JsonManagedReference
private List < X > xxB;
........ getters setters
}
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
public class A implements Serializable {
........
//bi-directional many-to-one association to BookedClient
@OneToMany(mappedBy = "a", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JsonManagedReference
private List < X > xxA;
........ getters setters
}
错误:
com.fasterxml.jackson.databind.JsonMappingException:多个名为“defaultReference”的反向引用属性
如何解决此错误?我不能在一个类中使用多个反向引用吗?
【问题讨论】: