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

Reply via email to