0
我想A類與C類 和B類的集合與C類的集合映射映射重複列地圖2個實體第三人給hibernate.MappingException:對於實體
這裏是我的實體:
@Entity
@Table(name = "a")
Class A:
...
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "objectid" , nullable = false, updatable = false)
@Where(clause = "field= 'x'")
private Set<C> cSet = new HashSet<>();
@Entity
@Table(name = "b")
Class B:
...
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "objectid" , nullable = false, updatable = false)
@Where(clause = "field= 'x'")
private Set<C> cSet = new HashSet<>();
@Entity
@Table(name = "c")
Class C:
...
@Column(name = "objectid")
private String objectid;
我有一個例外:
hibernate.MappingException: Repeated column in mapping for entity: C column: objectid (should be mapped with insert="false" update="false")
我嘗試使用referencedColumnName EX:
Class A:
...
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "objectidA" ,referencedColumnName="objectid", nullable = false, updatable = false)
@Where(clause = "field= 'x'")
private Set<C> cSet = new HashSet<>();
沒有成功。 有什麼建議嗎?
這將如何工作?表C中FK參考objectId 1中的項目將與ID爲1的項目A和ID爲1的項目B相關聯。這真的是你想要的嗎? –