
|
If you were logged in you would be able to see more operations.
|
|
|
|
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.
|
|
Description
|
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. |
Show » |
Sort Order:
|