Hi,
I am seeing a strange interaction between child DataContexts and
localObject. If I set a to-one relationship from an object residing in a
child context to another object which lives in that context's parent, I see:
org.apache.cayenne.CayenneRuntimeException: [v.2.0.4 October 12 2007] Cannot
set object as destination of relationship abuseStatus because it is in a
different DataContext
So I do:
..verride
public void setToOneTarget(String relationshipName, DataObject value,
boolean setReverse) {
if (value != null && value.getDataContext() != this.getDataContext() &&
value.getDataContext() != this.getDataContext()) {
DataContext dc = getDataContext();
value = (DataObject) dc.localObject(value.getObjectId(), null);
}
super.setToOneTarget(relationshipName, value, setReverse);
}
in the child context object's class, which works fine (but seems like it
should not be necessary?).
But what I really want is:
DataContext refDataContext = DataContext.createDataContext();
CayenneDataObject ref = ...// get reference from refDataContext
DataContext userDataContext =
DataContext.createDataContext().createChildDataContext();
CayenneDataObject obj =
userDataContext.createAndRegisterNewObject(MasterObject.class);
obj.setRef(ref);
In other words, the obj's context (the child context) is not a child of the
referenced object's context.
In combination with the first bit of code, I now get:
org.apache.cayenne.validation.ValidationException: [v.2.0.4 October 12
2007] Validation has failed.
Validation failure for MasterObject.ref: "ref" is required.
because all the to-one relationship values set in this way are reset to null
during userDataContext.commitChanges()!
The stack looks like this:
MasterObject.setToOneTarget(UnAmourDataObject.java:11) *** value == null
in this call
org.apache.cayenne.access.ChildDiffLoader.arcCreated(ChildDiffLoader.java:120)
org.apache.cayenne.access.ObjectDiff$ArcOperation.apply(ObjectDiff.java:428)
org.apache.cayenne.graph.CompoundDiff.apply(CompoundDiff.java:97)
org.apache.cayenne.access.ObjectStoreGraphDiff.apply(ObjectStoreGraphDiff.java:136)
org.apache.cayenne.access.DataContext.onContextFlush(DataContext.java:1188)
org.apache.cayenne.access.DataContext.onSync(DataContext.java:1167)
org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1234)
org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1138)
Thoughts? Comments? Suggestions?
Thanks,
Marc
This archive was generated by hypermail 2.0.0 : Thu Nov 01 2007 - 17:43:40 EDT