我在一個類中有多個反向引用類。由於我爲他們使用了@JsonBackReference
,所以出現錯誤。我爲這些類分配了@JsonIdentityInfo
註釋,但我仍然得到相同的錯誤。名稱爲'defaultReference'的多個反向引用屬性
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: Multiple back-reference properties with name 'defaultReference'
我怎樣才能解決這個問題?我不能在課堂上使用多個後臺引用嗎?
我爲每個關係添加了一個名稱值。我仍然得到同樣的錯誤。 – Eniss
關於名稱'defaultReference'的同樣錯誤?奇怪 –
是的,我也試過'@JsonManagedReference(value =「a」)'''@JsonBackReference(value =「a」)',仍然是同樣的錯誤 – Eniss