问题
I have the following (simplified) situation:
Fields for TABLE A:
- ID
- COMMONID
Fields for TABLE AB:
- AID
- BID
COMMONID
Fields for TABLE B:
- ID
- COMMONID
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
What am I doing wrong? Consider that I'm new to Hibernate.
回答1:
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.
来源:https://stackoverflow.com/questions/14734235/org-hibernate-mappingexception-repeated-column-in-mapping-for-collection-using