-->
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.  [ 1 post ] 
Author Message
 Post subject: Bags and composite IDs
PostPosted: Sun Oct 22, 2006 6:59 pm 
Newbie

Joined: Thu May 20, 2004 7:39 am
Posts: 12
Hello!

I'm using hibernate 2.1.3 and have following problem:

There is a class Class1, which has properties prop1, prop2, prop3 which all constitute a composite id of Class1.

I have another class Class2 and Class2 has a bag of instances of Class2.

Each instance X in that bag (X instanceof Class2) has X.prop1 = Class2.id.

Class2 has a normal ID.

I have following XML definitions:

Class1:


Code:
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

   <class name="Class1"
      table="tbl_pred_seq" discriminator-value="N">
      
      <composite-id>
           <key-property name="predSeqPos" column="pred_seq_pos"/>
           <key-property name="id" column="ID_pred_seq"/>
           <key-many-to-one name="joining" class="Class2" column="ID_joining"/>
           <key-many-to-one name="prevJoining" class="Class2" column="ID_prev_joining"/>
      </composite-id>
   </class>
</hibernate-mapping>



Class2:

Code:
<bag name="predecessorSequence" table="tbl_pred_seq"
         cascade="save-update">
         <key column="ID_joining" />
         <many-to-many
            class="Class1" />
      </bag>


With these definitions I get this exception:

Code:
net.sf.hibernate.MappingException: Foreign key (tbl_pred_seq [elt])) must have same number of columns as the referenced primary key (tbl_pred_seq [pred_seq_pos,ID_pred_seq,ID_joining,ID_prev_joining])


How can I implement the bag in Class2 without modifying the database?

TIA

Dmitri

_________________
Dmitri Pissarenko
Software Engineer
http://dapissarenko.com


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

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.