db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Braeuchi <jbraeu...@gmx.ch>
Subject PersistenceBrokerImpl#storeToDb (assigning reference fk)
Date Fri, 19 Sep 2003 19:14:52 GMT
hi all,

assigning  reference foreign keys  _before_ storing the references  does 
not work for the case christopher worley reported. see 'Extent problem 
with multiple classes and tables' in user list.

the testcase consists of three classes E,F1,G1 (F1 inherits from E, G1 
from 1F)  where E has an autoincremented pk . F1 and G1 refer to the 
superclass using an anonymous reference descriptor using the pk of the 
class.

when storing an object of G1 reference F1 and also E are stored 
correctly (F1 with the autoincremented pk from E) but  inserting G1 
fails, because the key is not set. see testcases _fails_... in class 
AnonymousFieldsTest.

i could solve the problem (well, it's not the first time i think it's 
solved) by adding the following  line in PersistenceBrokerImpl#storeToDb:

....
        // 2. store references (1:1) associations to avoid FK violations
        storeReferences(obj, cld.getObjectReferenceDescriptors());
       
 >>        // BRJ: some foreign key values are only known after store
 >>        assignReferenceFKs(obj, cld.getObjectReferenceDescriptors());

        // setreferenceFKs for auto_inc dbs - this can be ignored by hi 
low or any that do pre assignment
        try
....

the testcases pass without any big problems, but i'm not sure about 
possible side effects. 
why do we assignReferenceFK before storing ?

<class-descriptor
        class="org.apache.ojb.broker.ObjectRepository$E"
        table="TABLE_E">

        <field-descriptor
            name="id"
            column="ID"
            jdbc-type="INTEGER"
            primarykey="true"
            autoincrement="true"
        />

        <field-descriptor
            name="someSuperValue"
            column="SOMESUPERVALUE"
            jdbc-type="INTEGER"
        />
 </class-descriptor>

 <class-descriptor
        class="org.apache.ojb.broker.ObjectRepository$F1"
        table="TABLE_F1">

        <field-descriptor
            name="id"
            column="ID"
            jdbc-type="INTEGER"
            primarykey="true"
        />

        <field-descriptor
            name="someValue"
            column="SOMEVALUE"
            jdbc-type="INTEGER"
        />

          <reference-descriptor name="super"
              class-ref="org.apache.ojb.broker.ObjectRepository$E"
             auto-retrieve="true"
             auto-update="true"
             auto-delete="true">
            <foreignkey field-ref="id" />
          </reference-descriptor>
    </class-descriptor>


    <class-descriptor
        class="org.apache.ojb.broker.ObjectRepository$G1"
        table="TABLE_G1">

        <field-descriptor
            name="id"
            column="ID"
            jdbc-type="INTEGER"
            primarykey="true"
        />

        <field-descriptor
            name="someSubValue"
            column="SOMESUBVALUE"
            jdbc-type="INTEGER"
        />

          <reference-descriptor name="super"
              class-ref="org.apache.ojb.broker.ObjectRepository$F1"
             auto-retrieve="true"
             auto-update="true"
             auto-delete="true">
            <foreignkey field-ref="id" />
          </reference-descriptor>
    </class-descriptor>


jakob




---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message