Issue Details (XML | Word | Printable)

Key: CORE-3036
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Andy Jefferson
Reporter: Karl M. Davis
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
JPOX Core (ARCHIVED)

Bidirectional 1:N Children Lost After Saving Detached Copies

Created: 17/Oct/06 09:59 AM   Updated: 24/Jan/07 09:29 AM   Resolved: 20/Oct/06 06:12 AM
Component/s: JDO
Affects Version/s: 1.1.1, 1.1.4
Fix Version/s: None

File Attachments: 1. Zip Archive detachment-children-overwriting-testcase.zip (3 kB)

Environment: Windows XP Professional SP2, MySQL 4.1, x86

Forum Thread URL: http://www.jpox.org/servlet/forum/viewthread?thread=3850&lastpage=yes
Datastore: MySQL
Severity: Production


 Description  « Hide
When saving/reattaching an out-of-date (but not modified/dirty) detached instance of an object with a bidirectional inverse 1:N child collection, data is lost. Specifically, the old version of the child collection will always replace the newer one, leaving any child objects since then with a parent of NULL in the database. Here is a simplified example of what happens (please note that this is not the code included in the test case, though the both do the same thing):
ClinicDAO dao = new JpoxDAO();

Owner bob = new Owner();
bob.setFirstName("Bob");
dao.storeOwner(bob);
bob = (Owner)dao.getOwners().get(1);

Pet fido = new Pet();
fido.setName("fido");
fido.setOwner(bob);
dao.storePet(fido);

dao.storeOwner(bob);

bob = (Owner)dao.getOwners().get(0);
if(bob.getPets().size() != 1)
throw new AssertionError("children of the detached instance have been overwritten");

This code will fail the assertion every time.
Attached is a test case using the inverse deck of cards sample. The URL I listed points to the forum thread I initially brought up this issue on.

Sort Order: Ascending order - Click to sort in descending order
Andy Jefferson added a comment - 20/Oct/06 06:12 AM
Issue is down to not assigning both ends of relation.