Hibernate version: 2.1.6
Hi,
i know, that my problem is not really a 'hibernate'-problem, but perhaps someone has an idea i don't had... and perhaps it's not possible to handle it 'automatically' ... or there's a workaround ...
I've got a Class A with some attributes:
Code:
/**
* many-to-one --> Class B
* not-null=false
* outer-join=true
* insert=false
* update=false
* -----------------------
* many-to-one --> Class C
* not-null=false
* outer-join=true
* insert=true
* update=true
*/
public class A {
private int id; // the pk
private int attr1;
private int attr2;
private String attr3;
private String attr4;
....
}
and a Class B and C with a composite-primary-key ...
Code:
public class B {
private int attr1; // part of composite-id
private int attr2; // part of composite-id
private String attr3; // part of composite-id
....
}
public class C {
private int attr1; // part of composite-id
private int attr2; // part of composite-id
private String attr3; // part of composite-id
private String attr4; // part of composite-id
....
}
Class A has references to:
* Class B --> attr1, attr2 and attr3 are columns in 'many-to-one'-relationship.
* Class C --> attr1, attr2, attr3 and attr4 are columns in 'many-to-one'-relationship.
My problem is, that 3 values are part of 2 references ... one many-to-one-reference contains of 3 columns and the other of 4.
Everything works fine ... i can insert, update and delete ... no problem. Load Class A works fine, too when an entry for Class B and Class C is available in DB.
The problem occurs when i try to load Class A and no entry for Class C is available ...
Hibernate tries to load Class C though 'outer-join' is set to 'true' and i will get an exception.
I think hibernate do try loading Class C because parts of the key-values are set (attr1, attr2 and attr3 are set because an entry for Class B is available) ...
My question is, if i can 'tell' hibernate some way, that it should not try to load Class C if not all 4 keys are set to 'not null', or much better to a defined value?
Perhaps i can extend an existing class? If so, what would be a good point to look at?
If there's no way (i don't think it's a 'good' reference-mapping) to load this relationship automatically, i will load it 'by hand' in my persistence-layer ... but, if possible, it would be great to let hibernate do this work ...
Every help is welcome :)
thx!
curio
P.S.: And no ... i'm not allowed to change the db ;)