mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-21 03:44:21 +00:00
Fix for #70 - @PrivateOwned makes Ebean try to remove non persistent objects from DB and throws OptimisticLockException
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user