Hi,

Since I am having problems with referential integrity violations when 
deleting objects I tried to understand the reorder() method in 
org.apache.ojb.odmg.ObjectEnvelopeTable. 

>From what I understand, the way this reordering is implemented leads to a 
strong bias of the final order towards the initial order. And the initial 
order results from the order in which TransactionImpl.register() adds 
objects to the ObjectEnvelopeTable. This initial order is good for inserts 
and updates, but bad for deletes. And the current reorder method cannot 
resolve this anymore. 

A simple example: 

Say object A has a reference to object B: 
        A->B.
When A receives a write lock, TransactionImpl will first add its 
references and then the object itself to the ObjectEnvelopeTable. So we 
have the order 
        [B,A].
Now we say db.deletePersistent(A) and db.deletePersistent(B) (in any 
order) and commit. The reorder method now first takes B, finds it needs 
deleting and that it has no references. So it just puts it first into the 
reordered list:
        [B]
Now reorder() takes A, finds it also needs deleting and that it has a 
reference to B. So it 'knows' that A should be deleted first and adds A to 
the vector. 
        [B,A]
Then it would add B after A to the vector, but B has already been handled, 
so it leaves it where it is. So we end up with the same order as 
initially, which is the wrong order for deletes.

I understand that in general there is no unique solution for ordering the 
objects so that no referential integrity contraints are violated (the 
simple case A<->B is unsolvable). But my feeling is that there should be a 
better solution, which would at least resolve the simple A->B case 
correctly.

Is this a known problem? Are there any plans to improve on this? I'm 
thinking of trying to work out a better solution, but currently I'm not 
sure how complex this would be.

I'm looking forward to hearing opinions about this.
Gerhard

Reply via email to