Have been digging around the dataContext and I saw this in the localObject
method
// TODO: Andrus, 1/24/2006 implement smart merge for modified
objects...
if (cachedObject != prototype
&& state != PersistenceState.MODIFIED
&& state != PersistenceState.DELETED) {
I believe this may be causing one of the problems below. If you call
localObject with a new object and a prototype then the checks above are true
and as a result this gets called further down the chain in the same method
descriptor.shallowMerge(prototype, cachedObject);
which sets all the relationships to faults and this breaks because the new
object is not committed.
Is this a bug? What is the real purpose of passing a prototype?
On 05/01/07, edward pedersson <cpsmadnes..ooglemail.com> wrote:
>
> Hi
>
> I am using the latest version of Cayenne with Tapestry 4.0.1.
>
> I am having a bit of trouble using nested dataContexts. I would like the
> user to be able to create a new object in a wizrd style application but have
> the option to cancel half way through the stages.
>
> I have tried a few different options and noe seem to work. In the first
> instance I tried the nested datacontext like this:
>
> AClass parent; //assume this exists and is in the threaded context
>
> DataContext childContext = this.getDataContext().createChildContext() //
> this.getDataContext() is the threaded context
>
> AnotherClass newObject =
> (AnotherClass)childContext.createAndRegisterNewObject(AnotherClass.class);
> AClass localParentObject = (AClass)childContext.localObject(
> parent.getObjectId(),null);
>
> object.setParent(localParent);
>
> //do other stuff here like set other properties
>
> // now save to parent
>
> childContext.commitChangesToParent();
>
> For some reason I seem to get the parent having two children, not just the
> one! I assume it is because the changes in the childContext are propagated
> to the parent context so as a result the first setParent call adds the child
> to the parent and on commit changes the child is added again to the parent.
>
> So I tried to have separate dataContexts instead by doing this
>
> DataContext anotherContext = DataContext.createDataContext()
>
> AnotherClass newObject =
> (AnotherClass)anotherContext.createAndRegisterNewObject(AnotherClass.class
> );
> AClass localParentObject = (AClass)anotherContext.localObject(
> parent.getObjectId(),null);
>
> object.setParent(localParent);
>
> //do other stuff here like set other properties
>
> // now save to parent
> newObject = (AClass)this.getDataContext().localObject(
> newObject.getObjectId(),null);
>
>
> I get errors like Can't build a query for relationship '...' for temporary
> id:
>
> Does anyone knew what I am doing wrong?
>
> many thanks for your help.
>
> --
>
>
> -- e
---- e
This archive was generated by hypermail 2.0.0 : Mon Jan 08 2007 - 04:48:42 EST