本文介绍了org.hibernate.MappingException:使用@JoinTable进行收集的映射中的重复列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下(简化)情况:
I have the following (simplified) situation:
表A的字段:
- ID
- COMMONID
表AB的字段:
- AID
- 出价COMMONID
- AID
- BIDCOMMONID
表B的字段:
- ID
- COMMONID
,并希望使用这样的OneToMany将其与实体映射(在映射到表A的主类中):
and want to map it with entities using a OneToMany like this (in the master class mapped on table A):
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = false, fetch = FetchType.LAZY)
@JoinTable(name = "AB",
joinColumns= {
@JoinColumn(name = "AID", referencedColumnName="ID"),
@JoinColumn(name = "COMMONID", referencedColumnName="COMMONID")},
inverseJoinColumns = {
@JoinColumn(name = "BID", referencedColumnName="ID"),
@JoinColumn(name = "COMMONID", referencedColumnName="COMMONID")})
private Set<MyClassForB> list= new HashSet<MyClassForB>();
建立会话时,出现以下错误:
Building the session, I obtain the following error:
org.hibernate.MappingException: Repeated column in mapping for collection using @JoinTable list column: COMMONID
我做错了什么?认为我是Hibernate的新手.
What am I doing wrong? Consider that I'm new to Hibernate.
推荐答案
尝试添加可插入且可更新的内容
Try to add insertable, and updateable like this
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = false, fetch = FetchType.LAZY)
@JoinTable(name = "AB",
joinColumns= {
@JoinColumn(name = "AID", referencedColumnName="ID", insertable = false, updatable = false),
@JoinColumn(name = "COMMONID", referencedColumnName="COMMONID", insertable = false, updatable = false)},
inverseJoinColumns = {
@JoinColumn(name = "BID", referencedColumnName="ID", insertable = false, updatable = false),
@JoinColumn(name = "COMMONID", referencedColumnName="COMMONID", insertable = false, updatable = false)})
private Set<MyClassForB> list= new HashSet<MyClassForB>();
但是我不确定您是否能够更新此设置,我的用例是只读的.
But I'm not sure whether you will able to update this set, my use case was read only.
这篇关于org.hibernate.MappingException:使用@JoinTable进行收集的映射中的重复列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!