You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Jakob Braeuchi <jb...@gmx.ch> on 2003/09/19 21:14:52 UTC
PersistenceBrokerImpl#storeToDb (assigning reference fk)
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
Re: PersistenceBrokerImpl#storeToDb (assigning reference fk)
Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi all,
i just commited this patch to the repository.
jakob
Jakob Braeuchi wrote:
> hi all
>
> i changed the sequence of storing an object the way i mentioned in my
> previous post. and it works
> imo it's the first time PersistenceBrokerImpl is getting smaller ...
> until we really split it up.
>
> please have a very close look at it and report any problem, because
> this is one of the critical parts of ojb !
>
> jakob
>
> Jakob Braeuchi wrote:
>
>> hi all,
>>
>> please have a look at method assertFkAssignment. it's based on
>> christopher worleys patch.
>> this fix runs ok for AnonymousFieldTest and
>> BidirectionalAssociationTest.
>>
>> jakob
>>
>> Jakob Braeuchi wrote:
>>
>>> 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
>>>
>>>
>> ------------------------------------------------------------------------
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-dev-help@db.apache.org
>>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-dev-help@db.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org
Re: PersistenceBrokerImpl#storeToDb (assigning reference fk)
Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi all
i changed the sequence of storing an object the way i mentioned in my
previous post. and it works
imo it's the first time PersistenceBrokerImpl is getting smaller ...
until we really split it up.
please have a very close look at it and report any problem, because this
is one of the critical parts of ojb !
jakob
Jakob Braeuchi wrote:
> hi all,
>
> please have a look at method assertFkAssignment. it's based on
> christopher worleys patch.
> this fix runs ok for AnonymousFieldTest and
> BidirectionalAssociationTest.
>
> jakob
>
> Jakob Braeuchi wrote:
>
>> 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
>>
>>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-dev-help@db.apache.org
>
Re: PersistenceBrokerImpl#storeToDb (assigning reference fk)
Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi all,
please have a look at method assertFkAssignment. it's based on
christopher worleys patch.
this fix runs ok for AnonymousFieldTest and BidirectionalAssociationTest.
jakob
Jakob Braeuchi wrote:
> 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
>
>