(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,