Fix for #70 - @PrivateOwned makes Ebean try to remove non persistent objects from DB and throws OptimisticLockException

This commit is contained in:
Rob Bygrave
2014-03-15 13:48:56 +13:00
parent 5bd454bdc0
commit f0dd069ed2
2 changed files with 10 additions and 1 deletions
@@ -764,7 +764,14 @@ public final class DefaultPersister implements Persister {
// increase depth for batching order
t.depth(+1);
for (Object removedBean : modifyRemovals) {
deleteRecurse(removedBean, t);
if (removedBean instanceof EntityBean) {
EntityBean eb = (EntityBean)removedBean;
if (eb._ebean_getIntercept().isLoaded()) {
// only delete if the bean was loaded meaning that
// it is know to exist in the DB
deleteRecurse(removedBean, t);
}
}
}
t.depth(-1);
}
@@ -29,12 +29,14 @@ public class TestPrivateOwnedIgnoreTransientOrphan extends BaseTestCase {
master1 = Ebean.find(master0.getClass(), master0.getId());
// Add then remove a bean that was never saved (to the DB)
master1.getDetails().add(new TSDetail());
master1.getDetails().clear();
try{
Ebean.save(master1);
} catch (OptimisticLockException exception) {
// Occured when the "unsaved" bean was wrongly being deleted
Assert.fail("Optimistic lock exception wrongly thrown: " + exception.getMessage());
return;
}