-->
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.  [ 4 posts ] 
Author Message
 Post subject: Design problem
PostPosted: Thu Feb 02, 2006 12:10 pm 
Newbie

Joined: Thu Feb 02, 2006 9:39 am
Posts: 19
(Hibernate v3)

I have some problem to define a composite-id on a self-referencing object. Maybe this is just an impossible design, but let me explain the case :

This object ("features") have two properties defining it's own identity:
- its name (a string)
- its father (which is itself a "features" object).

So 2 features are equals if they share the same name, and the same father.

I defined a composite-ID with this two properties such as below:
Code:
<hibernate-mapping>
<class table="feature" name="Feature" proxy="Feature">
   <composite-id name="id" class="FeaturePK">
      <key-property name="name" column="featureName" type="string" />
      <key-many-to-one name="fatherFeature" class="Feature" >
         <column name="idFatherFeature"/>
      </key-many-to-one>
   </composite-id>
</class>
</hibernate-mapping>

If I use such an hbm (with matching java classes), I got the message :
Code:

org.hibernate.MappingException: Foreign key (FK:feature [idFatherFeature])) must have same number of columns as the referenced primary key (feature [featureName,idFatherFeature])

which is totaly understandable.

But if I put another column in the key-many-to-one, it does not change a thing since the key-many-to-one will miss the newly put column in its definition.

Does anybody has any clues ? Does it exist a way to use a composite-id self referencing itself ?

I'm quite new to hibernate, so maybe I am missing something obvious.

Any help or pointer will be appreciate,


Top
 Profile  
 
 Post subject: up
PostPosted: Fri Feb 03, 2006 10:53 am 
Newbie

Joined: Thu Feb 02, 2006 9:39 am
Posts: 19
Maybe my question is not clear since I got no answer yet, so let me know if you need extra explantations.

Thanks,


Top
 Profile  
 
 Post subject: self referencing
PostPosted: Fri Feb 03, 2006 3:14 pm 
Newbie

Joined: Thu Dec 29, 2005 10:36 am
Posts: 5
Hi.

You should give more details regarding what you exactly want to do when you tell us with self referencing.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 5:39 am 
Newbie

Joined: Thu Feb 02, 2006 9:39 am
Posts: 19
Self-referencing means that my object "feature" have a relation with another "feature" object (its father). This design does not represent any problem at all. Hibernate create a column to reference its father ID, and everything's alright.

The problem occurs when I want to define a feature by its father. It's not anymore a property ("many-to-one") but a part of a composite-id (a "key-many-to-one").


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