Hi,

This seems like such a basic question that I probably shouldn¹t have to ask,
but I want to verify intended behavior versus a bug.  Since Cayenne doesn¹t
allow one to associate two data objects from distinct contexts, we use local
object.

So, I have something similar to the following:

ObjectContext customerContext;
Customer customer = customerContext.newObject(Customer.class);

ObjectContext childContext = customerContext.createChildDataContext();
BillingInfo bi = childContext.newObject(BillingInfo.class);

The bi instance is created in its own context so that if the user doesn¹t
commit the page, I can toss the data without affecting the customer context.
If the user does save the form, then I want to do something like
bi.setCustomer(customer);  However, they¹re in different contexts, so that
doesn¹t work.  Additionally, bi has relationships to other entities in
childContext.  So, in this case, I use localObject to pull customer into
childContext, set the relationship, commit, and go on my merry way.

The problem is that calling customer.getBillingInfo() now returns billing
info associated with the child context.  I thought that they would be HOLLOW
objects resolved with the customer¹s context, but it appears due to caching
I now have a situation that Cayenne normally won¹t allow: two related
objects in different contexts.

Is this the way it¹s supposed to work for child contexts or have I run into
a bug?  Either way, I¹ll need to fix it.  I just need to know which codebase
to work with.

Thanks,
Kevin

Reply via email to