Fix for #83 - Bug: Stateless update cascading to OneToOne or ManyToOne incorrectly tries to INSERT rather than UPDATE

This commit is contained in:
Rob Bygrave
2014-04-23 02:31:08 +12:00
parent f4357c2767
commit 654b10154e
6 changed files with 22 additions and 30 deletions
@@ -26,15 +26,13 @@ public class TestReferenceWithConstructorProperties extends BaseTestCase {
Set<String> loadedProps = beanState.getLoadedProps();
Assert.assertEquals(1, loadedProps.size());
Assert.assertTrue(beanState.isReference());
// read the status invokes lazy loading
order.getStatus();
BeanState beanState2 = Ebean.getBeanState(order);
// fully loaded
Assert.assertNull(beanState2.getLoadedProps());
Assert.assertFalse(beanState.isReference());
}
}
@@ -46,8 +46,17 @@ public class TestTextJsonReferenceBean extends BaseTestCase {
EntityBean eb = (EntityBean)refProd;
prodDesc.isReference(eb._ebean_getIntercept());
BeanState beanState = Ebean.getBeanState(refProd);
Assert.assertTrue(beanState.isNew());
String name = refProd.getName();
Assert.assertNotNull(name);
Assert.assertNull(name);
// Set to be 'loaded' to invoke lazy loading
beanState.setLoaded();
String name2 = refProd.getName();
Assert.assertNotNull(name2);
}
List<Order> orders = Ebean.find(Order.class)
@@ -47,21 +47,15 @@ public class TestJsonStatelessUpdate extends BaseTestCase {
// The update below cascades to also save "master" and that fails
// as it thinks it should INSERT master rather than UPDATE master
// Ebean.update(two2);
Ebean.update(two2);
// The following is a workaround, to explicitly update master first
// so then Ebean doesn't try to save it when two2 is updated
Ebean.beginTransaction();
try {
UUOne master = two2.getMaster();
Ebean.update(master);
Ebean.update(two2);
} finally {
Ebean.endTransaction();
}
// confirm the properties where updated as expected
UUTwo twoConfirm = Ebean.find(UUTwo.class, two.getId());
Assert.assertEquals("twoNameModified", twoConfirm.getName());
Assert.assertEquals("oneNameModified", twoConfirm.getMaster().getName());
}
}