I have a class A, that contains a Map. The values of that Map are instances of class B. Class B contains a reference to a class C (many-to-one). The key to the Map is a member of class C.
Classes (they all have the appropriate ids, constructors, setters and getters):
class A {
Map bs;
}
class B {
C c;
}
class C {
String name;
}
Tables:
CREATE TABLE A (
id BIGINT PRIMARY KEY,
description TEXT
);
CREATE TABLE B (
id BIGINT PRIMARY KEY,
aId BIGINT REFERENCES A,
cId BIGINT REFERENCES C,
description TEXT
);
CREATE TABLE C (
id BIGINT PRIMARY KEY,
name VARCHAR(64)
);
So C's HBM is pretty straightforward:
<class name="C" table="C">
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="name" type="text" column="name" />
</class>
B's seems pretty straightforward as well
<class name="B" table="B">
<id name="id" column="id">
<generator class="increment" />
</id>
<many-to-one name="C" column="cId" class="C" lazy="false" />
</class>
But I can't figure out what to do for A's HBM. I think it needs to look something like:
<class name="A" table="A">
<id name="id" column="id">
<generator class="increment" />
</id>
<map name="bs" table="B" lazy="false" fetch="join">
<key column="aId" />
<map-key type="string" formula="???????" />
<one-to-many class="B" />
</map>
</class>
But I can't figure out how to define the formula, or what the alternative representation that doesn't need a formula.
Any thoughts? Thanks!
|