MappingException: Repeated column in mapping for collection ManyToMany


#1

I have a ManyToMany mapping like this (I have changed the name of columns and properties):

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(
			name="ACTION_COMPANY_CONTACTS",
			joinColumns={
					@JoinColumn(name="ID_ACTION", referencedColumnName="ID_ACTION"),
					@JoinColumn(name="ID_COMPANY", referencedColumnName="ID_COMPANY"),
					@JoinColumn(name="TYPE", referencedColumnName="TYPE")
			},
			inverseJoinColumns={
					@JoinColumn(name="ID_CONTACT", referencedColumnName="ID_CONTACT"),
					@JoinColumn(name="TYPE", referencedColumnName="TYPE")
			})
	private List<Contact> contacts;

But I get the exception:

org.hibernate.MappingException: Repeated column in mapping for collection: mypackage.ActionCompany.contacts column: TYPE

It is possible to declare a ManyToMany mapping with the same column used in in both joinColumns oand inverseJoinColumns? If not, is there some alternative?

I have already tried to use insertable and updatable = false in one of the join declarations for column TYPE, but I still get the same exception.


#2

This sounds like a limitation. Please write a replicating test case and open a Jira issue with the test attached.

Meanwhile, you can work around this issue by mapping the intermediary table as an entity. The intermediary entity will have 2 @ManyToOne associations to the Contact and Action entities while the Contact and Action entities will have @OneToMany mappedBy associations.

For more details about this mapping, check out this article.