I am using hibernate 2.1.1, Ant 1.6, and xdoclet 1.2.
I have been unable to xdoclet generate my hibernate mapping docs correctly for a bidirectional many-to-many relationsip.
I have three tables: LEFT, CENTER, and RIGHT
The LEFT and RIGHT tables each contain an ID column and the CENTER table contains LEFT_ID and RIGHT_ID columns.
My POJOs relationships are setup like:
Code:
Left.java:
/**
* @hibernate.set table="CENTER" lazy="true"
* @hibernate.collection-key column="LEFT_ID"
* @hibernate.collection-composite-element class="test.Center"
*/
public Set getCenter() { return center; }
----------------------
Right.java
/**
* @hibernate.set table="CENTER" lazy="true"
* @hibernate.collection-key column="RIGHT_ID"
* @hibernate.collection-composite-element class="test.Center"
*/
public Set getCenter() { return center; }
----------------------
Center.java
/**
* @hibernate.many-to-one class="test.Left" column="LEFT_ID"
*/
public Left getLeft() { return left; }
/**
* @hibernate.many-to-one class="test.Right" column="RIGHT_ID"
*/
public Right getRight() { return right; }
What this generates is:
Code:
Left.hbm.xml:
<set name="center" table="CENTER" lazy="true" inverse="false" cascade="none" sort="unsorted">
<key column="LEFT_ID"/>
<composite-element class="test.Center">
<many-to-one name="left" class="test.Left" cascade="none" outer-join="auto" update="true" insert="true" column="LEFT_ID"/>
<many-to-one name="right" class="test.Right" cascade="none" outer-join="auto" update="true" insert="true" column="RIGHT_ID"/>
</composite-element>
</set>
and the same thing in Right.hbm.xml except the key column is RIGHT_ID.
Everything except the first many-to-one line in the mapping doc is correct. The many-to-one line respecifies the LEFT_ID that was already set in the key column and should not be generated. Xdoclet should not be including a many-to-one mapping when the class the mapping document is defining is the same as the many-to-one class.
The error i get from hibernate is:
Code:
Root Cause ::net.sf.hibernate.MappingException: Repeated column in mapping for collection: test.Left.center column: LEFT_ID
at net.sf.hibernate.collection.AbstractCollectionPersister.checkColumnDuplication(AbstractCollectionPersister.java:666)
at net.sf.hibernate.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:163)
at net.sf.hibernate.collection.BasicCollectionPersister.<init>(BasicCollectionPersister.java:35)
at net.sf.hibernate.persister.PersisterFactory.createCollectionPersister(PersisterFactory.java:54)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:148)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:739)
Am I setting this up the xdoclet tags incorrectly, or is xdoclet not generating the mapping docs correctly.
Thanks for your help,
-shreyank