Change the line that throws the exception --> newItem.setContact(item);
to:  newItem.setContact( getObjectContext().localObject( item ) );


-----Original Message----- From: Andrew Willerding
Sent: Thursday, March 3, 2016 4:16 PM
To: [email protected]
Subject: Re: No object is registered in context with Id

Here's the rest of the stack.

2016-03-03,09:05:44:433,ERROR,[Thread-15],,'com.callistacti.vaadinLib.IWindowEditBase'
ERROR:ObservableComponent Error processing observer's update code.
Observer==>class
com.itsurcom.bluecranex.GUI.Panels.PanelProjectContacts::org.apache.cayenne.CayenneRuntimeException:
[v.4.0.M3 Feb 08 2016 17:09:41] No object is registered in context with
Id <ObjectId:Contact, ContactID=1922>
    at
org.apache.cayenne.access.ObjectStore.registerDiff(ObjectStore.java:162)
    at
org.apache.cayenne.access.ObjectStore.arcCreated(ObjectStore.java:974)
    at
org.apache.cayenne.util.ObjectContextGraphAction.handleArcPropertyChange(ObjectContextGraphAction.java:88)
    at
org.apache.cayenne.util.ObjectContextGraphAction.handlePropertyChange(ObjectContextGraphAction.java:65)
    at org.apache.cayenne.BaseContext.propertyChanged(BaseContext.java:460)
    at
org.apache.cayenne.CayenneDataObject.addToManyTarget(CayenneDataObject.java:248)
    at
org.apache.cayenne.CayenneDataObject.setReverseRelationship(CayenneDataObject.java:417)
    at
org.apache.cayenne.CayenneDataObject.setToOneTarget(CayenneDataObject.java:372)
    at
com.itsurcom.bluecranex.database.auto._ProjectContact.setContact(_ProjectContact.java:44)

The reason I was setting all the objects to use the same ObjectContext
was that the objects themselves are setup in multiple threads and I was
getting ObjectContext errors.

Here is the error I was trying to get around.

2016-03-03,09:12:20:135,ERROR,[Thread-25],,'com.callistacti.vaadinLib.IWindowEditBase'
ERROR:ObservableComponent Error processing observer's update code.
Observer==>class
com.itsurcom.bluecranex.GUI.Panels.PanelProjectContacts::org.apache.cayenne.CayenneRuntimeException:
[v.4.0.M3 Feb 08 2016 17:09:41] Cannot set object as destination of
relationship contact because it is in a different ObjectContext
    at
org.apache.cayenne.CayenneDataObject.willConnect(CayenneDataObject.java:399)
    at
org.apache.cayenne.CayenneDataObject.setToOneTarget(CayenneDataObject.java:355)
    at
com.itsurcom.bluecranex.database.auto._ProjectContact.setContact(_ProjectContact.java:44)

Using this code...

                ObjectContext oc = UI.getObjectContext();
                int addItemCount = 0;
                for (Contact item : list) {

                    ProjectContact newItem =
oc.newObject(ProjectContact.class);

                    //project.setObjectContext(oc);
                    //project.getCompany().setObjectContext(oc);
                    newItem.setCompany(project.getCompany());
                    //item.setObjectContext(oc);

exception-->newItem.setContact(item);
                    newItem.setProject(project);
newItem.setPrimeContact(ProjectContact.Type.NON_PRIME.getCode());
                    addItemCount++;
                }
            oc.commitChanges();



On 03/03/16 06:32 AM, Andrus Adamchik wrote:
Hi Andrew,

You don't show the relevant stack, so I can only guess. But I find the following code suspect:

    project.setObjectContext(oc);
    project.getCompany().setObjectContext(oc);
Setting ObjectContext explicitly on Persistent objects is never a good idea. Object should stay in the ObjectContext it was created in or fetched from). Any specific reason why you are doing that?

Andrus



On Mar 3, 2016, at 6:15 AM, Andrew Willerding <[email protected]> wrote:

I am stuck on exactly what this message means and how to correct the situation.

Here are my table relationships.

Project               ProjectContact         Contact
---------               --------------------         ----------
ProjectID <--->     ProjectID
                              ContactID    <--->  ContactID

Here is my code.

                ObjectContext oc = UI.getObjectContext();
                for (Contact item : list) {
ProjectContact newItem = oc.newObject(ProjectContact.class);
                    project.setObjectContext(oc);
                    project.getCompany().setObjectContext(oc);
                    newItem.setCompany(project.getCompany());
                    item.setObjectContext(oc);
exception->newItem.setContact(item);
                    newItem.setProject(project);
newItem.setPrimeContact(ProjectContact.Type.NON_PRIME.getCode());
                    addItemCount++;

Here's the exception that is thrown when the newItem.setContact(item) is executed.

2016-03-02,22:00:25:587,ERROR,[Thread-83],,'com.callistacti.vaadinLib.IWindowEditBase' ERROR:ObservableComponent Error processing observer's update code. Observer==>class com.itsurcom.bluecranex.GUI.Panels.PanelProjectContacts::org.apache.cayenne.CayenneRuntimeException: [v.4.0.M3 Feb 08 2016 17:09:41] No object is registered in context with Id <ObjectId:Contact, ContactID=1170>


Reply via email to