• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ManyToMany - Repeated column in mapping problem

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic