Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes ManyToMany - Repeated column in mapping problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "ManyToMany - Repeated column in mapping problem" Watch "ManyToMany - Repeated column in mapping problem" New topic
Author

ManyToMany - Repeated column in mapping problem

AnilPrakash Raju
Ranch Hand

Joined: Jul 26, 2004
Posts: 137
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

Joined: May 22, 2011
Posts: 27
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.


Have a look at my blog: http://automateddeveloper.blogspot.com/
Or even my Android Apps (website): http://www.mobile.thirdmindmedia.co.uk
AnilPrakash Raju
Ranch Hand

Joined: Jul 26, 2004
Posts: 137
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
 
wood burning stoves
 
subject: ManyToMany - Repeated column in mapping problem
 
Similar Threads
Hibernate I18N Repeated column with composite IDs
Simple JOIN in JPA proving difficult
How do I map composite primary key/foreign key
@PrimaryKeyJoinColumn: no insertable and no updatable
Column index not populated?