-->
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.  [ 5 posts ] 
Author Message
 Post subject: Repeated column in mapping for collection
PostPosted: Wed Dec 21, 2005 12:22 pm 
Newbie

Joined: Tue Aug 24, 2004 8:41 am
Posts: 15
Location: Amersfoort, the Netherlands
Hey everyone

I have the following mapping:

Code:
<class name="Order" table="SalesOrder">

   <list name="_orderLines" access="field" table="OrderLines" cascade="all" lazy="false" inverse="true">
      <key>
         <column name="orderId"/>
      </key>

      <index column="sequence"/>

      <composite-element class="OrderLine">

         <many-to-one access="field" name="_order" column="orderId" class="Order" not-null="true"/>

      </composite-element>
   </list>

</class>


It gives me the following error:

Code:
Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for collection: nl...domain.Order._orderLines column: orderId
   at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:275)
   at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:298)
...


Which is probably totally valid. But how can I mantain a reference from the OrderLine to the Order without creating an additonal column? Am I missing something?

Thanks in advance,
Vincent


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 12:52 pm 
Beginner
Beginner

Joined: Thu Sep 01, 2005 7:43 am
Posts: 31
Location: León (Spain)
Remember that composite-elements are value objects, and that means they'll be stored in the same table as the owning entity (the list), so you end up with 2 columns named orderId.

If you want to navigate from and OrderLine to an Order, consider dropping the composite-element or wait for a better answer ;-)

Bye.

_________________
Please rate...

Expert on Hibernate errors... I've had them all... :P


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 22, 2005 4:33 am 
Newbie

Joined: Tue Aug 24, 2004 8:41 am
Posts: 15
Location: Amersfoort, the Netherlands
Well, because I specified the 'table' element in the list, it would store the elements of the list in a different table. Besides that the sequence together with the orderId would become a composite key (kind of). I'm currently in the process of refactoring the database and giving hte composite element class its own <class></class> tags. Still, it seems to me that this should be possible, because the class is in fact in a different table.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 22, 2005 4:40 am 
Beginner
Beginner

Joined: Thu Sep 01, 2005 7:43 am
Posts: 31
Location: León (Spain)
Even if the list resides in its own table, that table has an id (named orderId) and the many-to-one (that resides in the same table) has another id column (named orderId also). That's why hibernate complains.

Bye.

_________________
Please rate...

Expert on Hibernate errors... I've had them all... :P


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 22, 2005 8:40 am 
Newbie

Joined: Tue Aug 24, 2004 8:41 am
Posts: 15
Location: Amersfoort, the Netherlands
Yes, but the orderId used to maintain the collection and the back-reference are the same... they should be the same. So, I don't want to create two the same columns, I just want to use it twice: as a reference to the order, and to maintain the order -> orderLine collection. The only difference is that I use composite-element instead of a separate class definition. The advantage would be that I can use the columsn sequence and orderId as a composite key for free.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.