Hi Brian Latimer!!
Once I've used a one-to-one mapping and I do the following:
Tables:
a.. create table A (id int primary key);
b.. create table B (id int primary key, foreign key (id) references a (id));
respository_user.xml:
<class-descriptor class="model.A" table="LAB.A">
<field-descriptor id="0"
name="id"
column="id"
jdbc-type="INTEGER"
primarykey="true"
/>
</class-descriptor>
<class-descriptor class="model.B" table="LAB.B">
<field-descriptor id="0"
name="id"
column="id"
jdbc-type="INTEGER"
primarykey="true"
/>
<reference-descriptor
name="a"
class-ref="model.A"
auto-insert="true"
>
<foreignkey field-ref="id"/>
</reference-descriptor>
</class-descriptor>
So, you have to work with the child class. Instantiate a class A and associate it to a
class B, then you can call the store(b) method.
A a = new A();
a.setId(1);
B b = new B();
b.setA(a);
store(b)
OJB will insert the parent first and then the child. But you can't forget the
auto-insert="true" tag!!!!
Hope it helps and sorry my english,
Fernando Bernardino
----- Original Message -----
From: "Brian Latimer" <[EMAIL PROTECTED]>
To: "OJB Users List" <[EMAIL PROTECTED]>
Sent: Wednesday, August 25, 2004 4:43 PM
Subject: Autoincriment FK and PK problem
>
> >in a DB2 databse
>
> >Table A has a PK named id that is also an identity (autoincriment) column
>
> Table B has a PK called id that is also a FK to table A's id field
>
> When attempting to insert Class A, which contains an instance of Class B,
> it seems that OJB attempts to insert class B before class A. This fails,
> as class A doesn't have a proper PK yet, and thus class B doesn't have a
> valid PK yet.
>
> given that I can't change my poorly designed database, is there anything I
> can do within OJB to get around this problem?
>
> Do I simply need to manually insert class A and B? That would be a shame,
> as the auto-update feature works great for instances of class A and B that
> already exist.
>
> any suggestions would be appriciated.
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>