-->
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.  [ 2 posts ] 
Author Message
 Post subject: many-to-many with list mapping problem (wrong PK generated)
PostPosted: Fri Feb 23, 2007 2:35 pm 
Newbie

Joined: Wed Jan 24, 2007 9:35 am
Posts: 7
Hi!

I have a textbook example of many-to-many bidirectional association. There's an author who creates items. The ordered end of the association is mapped using a list in the following manner (Item class):

Code:
<list name="Authors" table="CREATOR_C_ITEM" cascade="save-update">
      <key column="ITEM_ID"/>
      <index column="ITEM_POSITION"/>
      <many-to-many class="Creator" column="CREATOR_ID"/>
</list>


The unordered end is (Creator Class):
Code:
<set name="ItemsCreated" table="CREATOR_C_ITEM" inverse="true" cascade="save-update">
      <key column="CREATOR_ID"/>
      <many-to-many class="Item" column="ITEM_ID"/>
</set>


I would expect the link table to have the PK consisting of ITEM_ID and ITEM_POSITION, but the ddl generated is a bit different:

Code:
create table CREATOR_C_ITEM (
  ITEM_ID INTEGER not null,
   CREATOR_ID INTEGER not null,
   ITEM_POSITION INTEGER not null,
   primary key (CREATOR_ID, ITEM_ID)
);


Thus not allowing any duplicate fields, which is a nonsense for that type of collection. I've tested it on the 1.2Beta3 and the recent 1.2CR1. What is wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 23, 2007 4:34 pm 
Newbie

Joined: Wed Jan 24, 2007 9:35 am
Posts: 7
Ok, found a solution for the problem. It's rather obvious if you think about it. I was using a set, which doesn't allow duplicates and thus the PK of the join table is correct. Switching to bag (which allowes duplicates) solved the problem.


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