Hi Gonçalo,
Gonçalo Luiz wrote:
Hello,
I've been trying this for hours without minimal success... I have a
A<->B relation the simpliest thing one can imagine. Each class has a
foreign key pointing to each other (a has bKey and b has aKey).
The problem is that when I check the database only one of the
instances have its foreign key value, the other one is zero.
I'm attaching my repository file and my business class that is
persisting the objects.
The business class was not attached (only the metadata file). Could you
post the source code again.
I don't really understand why only one side of
the relation have the correct value.
In fact, in the attached files, I have some more occurencies of this
odd problem. However in 1:n bidirectional relationships its seems to
be no problem at all (maybe because there is only one foreign
key....).
I think this might be related to the fact that the value of a foreign
key is known only when the pointed instance is persisted... but how
can I fix this behaviour ?
Which version of OJB do you use?
And yes I'm using
auto-retrieve="true"
auto-update="none"
auto-delete="none"
as recomended.
So I assume you are using the ODMG-api - correct?
It's a bidirectional 1:1 relation, thus if A was written to database the
PK of B is still 'null', thus A get 'null' as FK to B (or vice versa).
You can use OJB's ODMG-Extensions to solve your problem. Here is an
example using class Shop and ShopDetail with bidirectional 1:1 reference:
CircularTest.Shop s1 = new CircularTest.Shop(name + "_1");
CircularTest.ShopDetail sd = new CircularTest.ShopDetail(name + "_1");
s1.setDetail(sd);
sd.setShop(s1);
TransactionExt tx = (TransactionExt) odmg.newTransaction();
tx.begin();
database.makePersistent(sd);
tx.flush();
database.makePersistent(s1);
tx.commit();
tx.begin();
database.deletePersistent(s1);
tx.flush();
database.deletePersistent(sd);
tx.commit();
regards,
Armin
Please let me know if yoy have any ideas.
Best regards,
--
Gonçalo Luiz
------------------------------------------------------------------------
<class-descriptor class="org.goncalo.smsbridge.domain.SmsBridge"
table="SMS_BRIDGE">
<field-descriptor
name="oid"
column="OID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<collection-descriptor
auto-retrieve="true"
auto-update="none"
auto-delete="none"
name="users"
element-class-ref="org.goncalo.smsbridge.domain.User">
<inverse-foreignkey field-ref="keyApplication"/>
</collection-descriptor>
</class-descriptor>
<class-descriptor class="org.goncalo.smsbridge.domain.User"
table="USER">
<field-descriptor
name="oid"
column="OID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor
name="keyApplication"
column="KEY_APPLICATION"
jdbc-type="INTEGER"
/>
<field-descriptor
name="keyPerson"
column="KEY_PERSON"
jdbc-type="INTEGER"
/>
<field-descriptor
name="username"
column="USERNAME"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="password"
column="PASSWORD"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="timesLoggedin"
column="TIMES_LOGGED_IN"
jdbc-type="INTEGER"
/>
<reference-descriptor
auto-retrieve="true"
auto-update="none"
auto-delete="none"
name="application"
class-ref="org.goncalo.smsbridge.domain.SmsBridge">
<foreignkey field-ref="keyApplication"/>
</reference-descriptor>
<reference-descriptor
auto-retrieve="true"
auto-update="none"
auto-delete="none"
name="person"
class-ref="org.goncalo.smsbridge.domain.Person">
<foreignkey field-ref="keyPerson"/>
</reference-descriptor>
</class-descriptor>
<class-descriptor class="org.goncalo.smsbridge.domain.Person"
table="PERSON">
<field-descriptor
name="oid"
column="OID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor
name="keyAddressBook"
column="KEY_ADDRESS_BOOK"
jdbc-type="INTEGER"
/>
<field-descriptor
name="keyUser"
column="KEY_USER"
jdbc-type="INTEGER"
/>
<field-descriptor
name="name"
column="NAME"
jdbc-type="VARCHAR"
/>
<reference-descriptor
auto-retrieve="true"
auto-update="none"
auto-delete="none"
name="addressBook"
class-ref="org.goncalo.smsbridge.domain.addressBook.AddressBook">
<foreignkey field-ref="keyAddressBook"/>
</reference-descriptor>
<reference-descriptor
auto-retrieve="true"
auto-update="none"
auto-delete="none"
name="user"
class-ref="org.goncalo.smsbridge.domain.User">
<foreignkey field-ref="keyUser"/>
</reference-descriptor>
</class-descriptor>
<class-descriptor class="org.goncalo.smsbridge.domain.addressBook.AddressBook"
table="ADDRESS_BOOK">
<field-descriptor
name="oid"
column="OID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor
name="keyOwner"
column="KEY_PERSON"
jdbc-type="INTEGER"
/>
<reference-descriptor
auto-retrieve="true"
auto-update="none"
auto-delete="none"
name="owner"
class-ref="org.goncalo.smsbridge.domain.Person">
<foreignkey field-ref="keyOwner"/>
</reference-descriptor>
</class-descriptor>
------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]