-->
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: Deriving a composite primary key
PostPosted: Mon Jan 10, 2005 12:30 pm 
Newbie

Joined: Mon Jan 10, 2005 12:27 pm
Posts: 1
Hibernate version: 2.1.7 DB: Oracle 9i

Hi, I am experiencing problems trying to derive a composite primary key from the id's generated by two other objects. These Id's are generated using a custom generator class.

For example, if I had an object C which takes a id generated from objects A and B, how do I get Hibernate to assign both of the new id's to the object C?

I can get it to work in the case of a normal one to many relationship but I'm not sure how to do it for two objects.

Here is an example of what I have tried.


<hibernate-mapping>
<class name="com.A" table="A">
<id name="aId" column="a_id">
<generator class="com.HibernateIdGenerator"/>
</id>
<bag name="Cs" table="C" access="field">
<key>
<column name="a_id"/>
</key>
</bag>
</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="com.B" table="B">
<id name="bId" column="b_id">
<generator class="com.HibernateIdGenerator"/>
</id>
<bag name="Cs" table="C" access="field">
<key>
<column name="b_id"/>
</key>
</bag>
</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="com.C" table="C">
<composite-id>
<key-property name="aId" column="a_id" access="field"/>
<key-property name="bId" column="b_id" access="field"/>
</composite-id>
</class>
</hibernate-mapping>


Does anyone if this is possible using an id generator?

Thanks,

Ian


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 10, 2005 5:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you must use a key-many-t-one

It is not possible to define an id geenrator for composite PK.
Cou can post it to JIRA as a feature request, and even better provide a patch :-)

_________________
Emmanuel


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.