Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ManyToMany - Repeated column in mapping problem

 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to do a @manyToMany mapping in my code and i am getting a org.hibernate.MappingException: Repeated column in mapping for collection error.

The table is I have got:

- Table PassengerSegmentVersion -primary keys {VersionStartDate, passengerID, SegmentID }
- Table PassengerLegVersion - primary keys {VersionStartDate, passengerID, SegmentID , InventoryLegID}
- Table InventoryLegVersion - primary keys {VersionStartDate, InventoryLegID }


In my PassengerSegmentVersion Class i have got :

@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "PassengerLegVersion",
joinColumns = {
@JoinColumn(name = "PassengerID", referencedColumnName = "PassengerID"),
@JoinColumn(name = "SegmentID", referencedColumnName = "SegmentID"),
@JoinColumn(name = "VersionStartDate", referencedColumnName = "VersionStartDate")},
inverseJoinColumns = {
@JoinColumn(name = "InventoryLegID", referencedColumnName = "InventoryLegID"),
@JoinColumn(name = "VersionStartDate", referencedColumnName = "VersionStartDate", insertable = false, updatable = false)}
)
private List<InventoryLegVersion> inventoryLegs = new ArrayList<InventoryLegVersion>();


I have read in other topics relating to this issue to use insertable = false and updatable = false. i have tried it but still getting same error. I have not included any mapping in the InventoryLegVersion class since i don't need to use it. Do i need to do it?

Any suggestions?

Thanks in advance

Anil
 
rob michael
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are trying to define a column named VersionStartDate twice.

@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "PassengerLegVersion",
joinColumns = {
@JoinColumn(name = "PassengerID", referencedColumnName = "PassengerID"),
@JoinColumn(name = "SegmentID", referencedColumnName = "SegmentID"),
@JoinColumn(name = "VersionStartDate", referencedColumnName = "VersionStartDate")},
inverseJoinColumns = {
@JoinColumn(name = "InventoryLegID", referencedColumnName = "InventoryLegID"),
@JoinColumn(name = "VersionStartDate", referencedColumnName = "VersionStartDate", insertable = false, updatable = false)
}


Those two columns are conflicting - name one of them differently and it should be ok.
 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob.

I can't change the names of the fields in the table. It is fixed. I tried to change the name of the columns eg.
@JoinColumn(name = "VersionStartDate1", referencedColumnName = "VersionStartDate", insertable = false, updatable = false)

But i got an error when i ran the application again

Invalid column name 'VersionStartDate1'
org.hibernate.exception.SQLGrammarException: could not initialize a collection:

thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic