7
我有一個有趣的問題。我的數據模型如下:春季數據序列化嵌入ManyToOne參考
A型:
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
public class A {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
}
B型:
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
public class B {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
}
嵌入式C:
@Embeddable
@JsonIgnoreProperties(ignoreUnknown = true)
public class C {
@ManyToOne
private A a;
@ManyToOne
private B b;
}
和類型d:
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
public class D {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ElementCollection
@OrderColumn(name = "ORDER_INDEX")
@CollectionTable(
name = "d_c_join",
joinColumns = @JoinColumn(name = "d_id")
)
private List<C> listOfC;
}
反序列化(並存儲)實體正常工作。當d類的一個對象被序列下面是結果:
{
"_embedded" : {
"ds" : [ {
"id" : 1,
"listOfC" : [ { }, { } ],
"_links" : {
"self" : {
"href" : "http://localhost:8000/ds/1"
}
}
} ]
}
}
我如何配置Spring-數據序列化A和B在C(最好是通過他們的URI)。
我認爲你只是標記爲eagerload C上的領域,對不對? –
沒有彈簧數據將看字段和引用不依賴於它正在渴望或延遲加載 – Benny
我有類似的問題。 @Embeddable對象中的關係沒有被序列化。你有沒有設法解決這個問題? –