Here's the situation: I have an entity class A. Inside it, it has a Map<Number, B> where B is another entity class. The number is stored as a property of B. B also stores a reference back to A.
So the tables look like:
Code:
A:
aID NUMBER(19, 0),
primary key(aID)
B:
bID NUMBER(19, 0),
aID NUMBER(19, 0),
mapKey NUMBER,
primary key(bID)
foreign key(aID references A)
In the Java code, I've got:
Code:
class A {
private Long aID;
private Map<Number, B> bMap; //Pretend I've got get/set methods
private B bDefault;
public B findB(Number mapKey) {
if (mapKey == null) {
return bDefault;
} else {
return getBMap().get(mapKey);
}
}
}
class B {
private Long bID;
private A parent;
private Number mapKey;
}
The problem is the bDefault property of A. The idea is that bDefault is the instance of B that I want to find when the mapKey Number is null. Obviously, I can't put it into the map because the key is null. So how do I map it in hibernate to get it to load & save properly? I can't use <one-to-one> because there's more than one entry in table B with the same aID. Is there a workaround that doesn't involve me making up a goofy number to substitute for null?
Thanks for your help,
Dan
[/code]