Hi Wes,
Lemke, Wesley wrote:
We have a 1-1 Relationship between GenericGroup and ClientBillingInfo. We have the client_billing_id in the generic_group table and the generic_grp_id in the client_billing table, because we need to traverse this relationship in both directions.
Our problem occurs when we save a GenericGroup. It will first save the
ClientBillingInfo object, so it puts -1 in the generic_grp_id field of
the client_billing table (We are using database generated keys).
You are using a circular reference and OJB starts insert with CBI object. This object has a 1:1 reference to GG, so the FK will be set. But the referenced GG wasn't persisted so far, but OJB use a temporary PK value for all non-persisted objects
(created by the used sequence-manager impl, see
http://db.apache.org/ojb/docu/guides/sequencemanager.html#Identity+based+sequence+manager
)
So the FK in CBI will assigned with the temporary PK value of GG. This shouldn't be a problem because on insert of GG this should be updated with real PK value.
If you want to avoid this you could force OJB to write CBI/GG first to DB and then set the reference:
TransactionExt tx = (TransactionExt) odmg.newTran.. tx.begin(); db.makePersistent(GG); tx.flush(); GG.set(CBI); CBI.set(GG); db.makePersistent(CBI); tx.commit();
regards, Armin
Most of the time this isn't that big of an issue, because we usually will save the GenericGroup object again, and at that time the generic_grp_id in the client_billing table gets updated to the correct value. However, this could cause problems in certain situations. Is there a work around for this problem?
Here are the relevant parts of the mapping file:
<class-descriptor class="com.lmig.pm.affinity.model.client.GenericGroup"
table="DEXA400T"
>
...
<field-descriptor
name="billingInfoId"
column="CLIENT_BILLING_ID"
jdbc-type="INTEGER"
access="anonymous"
/>
<reference-descriptor name="billingInfo"
class-ref="com.lmig.pm.affinity.model.client.ClientBillingInfo"
auto-update="true"
auto-delete="true">
<foreignkey field-ref="billingInfoId"/>
</reference-descriptor>
...
</class-descriptor>
<class-descriptor
class="com.lmig.pm.affinity.model.client.ClientBillingInfo"
table="DEXA500T"
>
...
<field-descriptor
name="groupId"
column="GENERIC_GRP_ID"
jdbc-type="INTEGER"
access="anonymous"
/>
<reference-descriptor name="group"
class-ref="com.lmig.pm.affinity.model.client.GenericGroup">
<foreignkey field-ref="groupId"/>
</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]
