openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpalache <>
Subject Data consistency issues while modifying collections.
Date Mon, 29 Jun 2009 19:30:24 GMT

There are data consistency issues when modifying more number of elements in a
collection Vs less number of elements.

Following is a detailed explanation about the issue with example:
- Entity A has a collection of Entities AItems with cascade ALL.
- Test case :
  Clear all the data inside tables representing Entity A and AItems.   
  Create 3 entity managers em1,em2 and em3.
      create A on em1 with id "1"
      add 10 elements of AItems (id's from 0-9) to the created A(id 1).
      persist A.
      merge A ( created in the previous step)
      Remove 3 elements of AItems from the merged A.
      Add 3 elements of AItems ( id's 10,11,12) to the merged A (id 1).
With out committing em1
      query database to fetch A and construct object result2 of entity A.
      Add 3 elements of AItems ( id's 13,14,15) to fetched A ( result2)       

   em2.commit ()
     query database to check the size of AItems that are related to A ( id
  The result on em3's query for AItems related to A, returns 13 as expected.
  13 ( Initial 10 - em1's 3 + em1's 3 + em2's 3).
When the same test case is repeated with removing and adding 10 elements
instead of 3 as before then I get wrong results.
    Add initial 10 AItems (id's 0-9) for A.
    em1 will remove 10 AItems from the collection of A.
    em1 will add 10 AItems (id's 10-19) to collection of A.
    em2 will add 10 AItems (id's 20-29) to collection of A.
    Commit em2.
    Commit em1.
    Then instead of 20 elements ( Initial 10 - em1's 10 + em1's 10 + em2's
10), I see only 10 elements.
    The 10 elements that I see are from em1's added AItems ( id's 10-19).

I think the cause of the issue is that, when more number of elements
(compared to initial element count of collection) in a collection are
modified then collection tracking is disabled and openJPA tries to do the
 -- Delete every thing from the collection
 -- Insert data back to collection.
While Inserting the data back it does not consider adding the dirty records
( em2's 10 added elements ) because the collection tracking is disabled.
I think the resolution is to enable collection tracking by default.

D:\openJPAsrc\openjpa_trunk\trunk>svn diff
(revision 78
(working cop
@@ -50,7 +50,7 @@
     protected Collection change = null;

-    private boolean _autoOff = true;
+    private boolean _autoOff = false;
     private boolean _track = false;
     private Boolean _identity = null;
     private int _seq = -1;

With the above change my test case is running fine.

Please let me know if you want me to open a JIRA for this issue.

View this message in context:
Sent from the OpenJPA Developers mailing list archive at

View raw message