Test case and fix for #113 (395) : On save @OneToOne does not cascade parent IDs to child node

This commit is contained in:
Rob Bygrave
2014-04-30 00:01:54 +12:00
parent 5049694fd3
commit 563293f7a9
5 changed files with 136 additions and 0 deletions
@@ -862,4 +862,18 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
EntityBean eb = (EntityBean)detailBean;
return targetDescriptor.isReference(eb._ebean_getIntercept());
}
/**
* Set the parent bean to the child bean if it has not already been set.
*/
public void setParentBeanToChild(EntityBean parent, EntityBean child) {
if (mappedBy != null) {
BeanProperty beanProperty = targetDescriptor.getBeanProperty(mappedBy);
if (beanProperty != null && beanProperty.getValue(child) == null) {
// set the 'parent' bean to the 'child' bean
beanProperty.setValue(child, parent);
}
}
}
}
@@ -558,6 +558,7 @@ public final class DefaultPersister implements Persister {
// skip saving this bean
} else {
t.depth(+1);
prop.setParentBeanToChild(parentBean, detailBean);
saveRecurse(detailBean, t, parentBean);
t.depth(-1);
}