Hibernate version: 2.1.7
hi,
i've got a many-to-one relation which i think is a little bit tricky and i haven't found a really satisfying solution so far ...
I've got two classes:
Code:
public ClassA {
Long id;
ClassB cb;
public void setCb(ClassB b) { this.cb = b; }
public ClassB getClassB() { return this.cb; }
}
public ClassB {
Long id;
....
}
So no problem so far (a many-to-one mapping for that case is quite simple and working - therefore no mapping-files) ...
The problem starts when i'm trying to load ClassA.
Imagine the following tables:
Code:
Table_ClassA
id NUMERIC (pk)
cb NUMERIC (fk to classB)
....
Table_ClassB
id NUMERIC (pk)
code NUMERIC (pk) :(
....
Table_A_Lot_of_Parameters
... somewhere in that table i'll find the currently right code to load ClassB ... :(
The steps to load ClassA must be the follwoing:
- determine the right code
- use a query to load ClassA
So far no problem, too ... in theory ;-)
my problem is, that the "many-to-one"-mapping in ClassA needs two column-definitions because ClassB has a composite-id ... but the required 'code' isn't persisted with ClassA ... therefore i'm not able to map this relation between ClassA and ClassB ... i could pass a constant value as 'code'-column, but that's not really what i want ...
Loading each Class on their own and setting ClassB to ClassA by hand is no problem, too but i would like to let hibernate do the work :)
But i'm standing on the line and have no idea how i could do that ... i'm pretty sure i've overlooked something or thinking to complex (confused ;) ) ...
could someone please push me into the right direction?
thanx!
curio