我想用A类集合映射A类。 和B类收集C类。
这是我的实体:
@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<>();
没有成功。 有什么建议吗?
答案 0 :(得分:0)
如果您删除了@JoinColumn
注释,那么您将获得join tables
,一个用于A-&gt; C,一个用于B-&gt; C,这应该能够做到你想要的,尽管我没有尝试过。