任何人都可以幫助我處理@Any
關係嗎?由於LazyInitializationException無法獲取@Any相關實體
我有一個接口InteractionParticipate
這是誰想要參與某種消息交互的一部分誰實現。消息由具有發射機和接收機的InteractionMessage
表示。由於我們不知道哪個實體實現InteractionParticipate
將成爲消息的接收者(或發送者),我們必須使用@Any
關係。
我已閱讀this one這啓發了我和InteractionMessage
類似的東西寫道:
@Any(metaColumn = @Column(name = "Transmitter_Type"))
@AnyMetaDef(
idType = "long",
metaType = "string",
metaValues = {
@MetaValue(value = "Applicant", targetEntity = Applicant.class),
@MetaValue(value = "Vacancy", targetEntity = Vacancy.class)
})
@JoinColumn(name = "Transmitter_Id")
@LazyToOne(LazyToOneOption.FALSE)
private InteractionParticipate transmitter;
@Any(metaColumn = @Column(name = "Receiver_Type"))
@AnyMetaDef(idType = "long", metaType = "string",
metaValues = {
@MetaValue(targetEntity = Applicant.class, value = "Applicant"),
@MetaValue(targetEntity = Vacancy.class, value = "Vacancy")
})
@JoinColumn(name = "Receiver_Id")
@LazyToOne(LazyToOneOption.FALSE)
private InteractionParticipate receiver;
數據庫中創建好,我可以看到實體保存正確。但是,當我嘗試從數據庫
InteractionMessage message = (InteractionMessage) session.get(InteractionMessage.class, id);
得到一個InteractionMessage
我的臉,我不能得到既不receiver
也不transmitter
因爲方法拋出「org.hibernate.LazyInitializationException」例外。無法評估...空缺_ $$ _ javassist_49.toString()。 (空缺職位正在實施InteractionParticipate
。)
我試圖玩@LazyToOne
甚至@LazyCollection
但失敗。
請幫我弄明白。提前致謝!