請告訴我是否可以覆寫“mappedBy”屬性。
在我的示例中,有兩個物體與另一個物體相關并且具有共同部分。為簡單起見,我將省略 id 和函式(getter 和 setter)等欄位。
兩位家長:
@Entity
public class Parent1 {
@Embedded
//I want to use sth like: AssociationOverride on "other" to mappedBy="parent1"
private Common common;
}
@Entity
public class Parent2 {
@Embedded
//I want to use sth like: AssociationOverride on "other" to mappedBy="parent2"
private Common common;
}
與@ManyToOne 關系:
@Entity
public class OtherEntity {
@ManyToOne
@JoinColumn(name="p_id_1")
private Parent1 parent1;
@ManyToOne
@JoinColumn(name="p_id_2")
private Parent2 parent2;
}
并且嵌入在父級中的共同部分:
@Embeddable
public class Common {
@OneToMany(mappedBy="IT_DEPENDS") //???
private OtherEntity other;
}
據我了解@AssociationOverride 僅適用于連接列或表。有沒有辦法覆寫 mappedBy 屬性?
uj5u.com熱心網友回復:
正如 jpa 規范中所述(參見第 2.7 節):
包含在元素集合中的可嵌入類(包括另一個可嵌入類中的可嵌入類)不得包含元素集合,也不得包含與多對一或一對一以外的物體的關系關系。可嵌入類必須在這種關系的擁有方,并且該關系必須由外鍵映射映射。
因此,您不能mappedBy在可嵌入類中使用一對多關系的一面。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/528169.html
標籤:爪哇春天休眠jpa
上一篇:錯誤碼如何設計才合理?
