Hibernate version: 2.1.6
Mapping documents:
only parts showing the relevant things ... i hope i have correctly pasted them ...
that works, but with the wrong primary key:
Part of Mapping for Class A:
Code:
<class
name="ClassA"
table="A"
mutable="false">
...
<many-to-one
name="classB"
class="ClassB"
insert="false"
update="false"
cascade="none"
property-ref="uniqueKey">
<column name="numberA"/>
<column name="276"/>
</many-to-one>
</class>
Part of Mapping for Class B
Code:
<class
name="ClassB"
table="B"
mutable="false"
>
<id ... (a field - just to have an pk declared in mapping-file) />
<component
name="uniqueKey"
class="BID">
<property
name="numberA"
column="numberA"
type="integer"
length="3"/>
<property
name="cuntryCode"
column="cuntryCode"
type="integer"
length="3"/>
</component>
...
</class>
that doesn't work, but the pk-definition is correct:Part of Mapping for Class A
Code:
<just the same ...>
Part of Mapping for Class B
Code:
<class
name="ClassB"
table="B"
mutable="false"
>
<composite-id
name="uniqueKey"
class="BID">
<key-property
name="numberA"
column="numberA"
type="integer"
length="3"/>
<key-property
name="cuntryCode"
column="cuntryCode"
type="integer"
length="3"/>
</component>
...
</class>
Question:Hi,
i've got only a little step to success :), but this step it seems for me, i can't go ...
The Situation:
I have to use a legacy db which i'm not allowed to change (even i really really would like to do :) ).
I have a Class A and a Class B.
Class A has a "many-to-one" relationship to Class B.
Tables:
Code:
-----
A
password VARCHAR (pk)
numberA integer (one part of the foreign key)
-----
B
numberA integer (pk)
cuntryCode integer (pk)
(some more data)
-----
My problem was, that one information in A is missing to uniquely identify B -> the countryCode.
Well, the countryCode is fix for my application, so i can use it as a constant-value.
Gavin gave the intial hint in
this thread.
Creating a "component" containg the two primary-key values of B works perfectly, but then i had to map a different primary key, because the
'many-to-one"-Mapping seems not to be allowed for a 'composite-id'. The Exceptions 'says', that there is no property "uniqueKey" in classB ... but it's there ... changing only the mapping-file to 'component' makes it work.
So my questions are:
1) is there a way to use my approach with the correct
'composite-id' to define my primary-key of ClassB?
2) is there a way to set the "countryCode" dynamically and not in mapping? Perhaps using a own 'Access'-implementation?
thx in advance!
carsten