Hi there,
I need some help persisting classes, where one class contains a list of
objects of the other class.
Say I have two classes A and B.
A has:
int id;
List bList; // a list of B objects.
B has:
int id;
A a; // a reference to the A that owns this B.
I am having trouble persisting these via ODMG. The only way I can get it to
work is if I also define a new field "aId" in class B (which is a copy of
the id from the A owner object).
Is there a "cleaner" way to get this to work (ie. without needing the "aId")
?
Eg. some tables:
CREATE TABLE A_TABLE(ID INTEGER)
CREATE TABLE B_TABLE(ID INTEGER,A_ID INTEGER)
In the repository xml:
<class-descriptor class="dk.pk.data.A" table="A_TABLE">
<field-descriptor name="id" column="ID" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
<collection-descriptor name="bList" element-class-ref="dk.pk.data.B">
<inverse-foreignkey field-ref="aId"/>
</collection-descriptor>
</class-descriptor>
<class-descriptor class="dk.pk.data.B" table="B_TABLE">
<field-descriptor name="id" column="ID" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
<field-descriptor name="aId" column="A_ID" jdbc-type="INTEGER"/>
<reference-descriptor name="a" class-ref="dk.pk.data.A">
<foreignkey field-ref="aId"/>
</reference-descriptor>
</class-descriptor>
Thanks,
Peter