-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Bidirectional composite element with xdoclet
PostPosted: Mon Mar 15, 2004 11:17 am 
Newbie

Joined: Fri Feb 20, 2004 12:23 pm
Posts: 10
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 15, 2004 11:27 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
if center doesn't contain any extra columns, you don't have to map a class to it, just use many-to-many between left & right

i use xdoclet too and it works fine except for composite id with joined subclasses :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 15, 2004 11:33 am 
Newbie

Joined: Fri Feb 20, 2004 12:23 pm
Posts: 10
My CENTER table actually does contain extra columns that i'm mapping as hibernate properties which are put into the composite-element by xdoclet. I just left them out of my post so it wouldn't get cluttered.

-shreyank


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.