[OJB-developers] Automatic Assignment of foreign keys and ODMG
Brought to you by:
thma
From: Bischof, R. <rai...@ed...> - 2002-01-04 11:13:43
|
Hi, I am trying to get automatic FK-assignment working with the ODMG interface and guess I found some bugs but I am not quite sure. My setup: I have a parent class with an auto-incremented PK named id which holds a collection of child objects. I have a child class has a PK that consists of parent_id (which is the ID of parent) and an additional String. It has it's own reference back to it's parent. I create a new parent and new children. The problem is that for new objects the sequence is: insert object, store references (where FK references are assigned), update the object. When the children are inserted their PK contains a parent_id 0. The method storeReferences updates the parent_id referencing to match the parent's id. Updating the child afterwards performs an "update ... where parent_id=123 and ...". This update does not match the child because the children have an (invalid) parent_id of 0, leaving DB state and OJB cache inconsistent. Another point is that you can't lock the children before they are stored as each of theoir PKs contains the invalid parent_id 0. I guess this works fine if the child object has it's own PK that does not include the reference to it's parent. Next bug seems to be that the FK assignment won't work if the children don't have references back to the parent. The children may be stored before the parent is stored, thus the FK assignment has not yet taken place, leaving the FK of all children invalid which are stored before the parent is stored. This is related to the missing direction in the object graph which causes the known foreign key violation bug. What about performing all FK assignment before the first object of a ODMG transaction is stored? Or when the object is locked? Any idea? Thanks Rainer Bischof |