Different DataContext

From: Reinout van Schouwen (reinou..mail.com)
Date: Wed Jul 22 2009 - 06:34:09 EDT

  • Next message: Emanuele Maiarelli: "Re: Different DataContext"

    Hi all,

    I hope someone can help me with the following issue. I'm using Cayenne
    with Databinder and Wicket for my application. In my model, multiple
    'PersName' objects can be associated to one 'Person'. But whenever I
    try to associate a newly created PersName with a Person, I get a
    CayenneRuntimeException:

    org.apache.cayenne.CayenneRuntimeException: [v.2.0.4 October 12 2007]
    Cannot set object as destination of relationship person because it is
    in a different DataContext
         at org.apache.cayenne.CayenneDataObject.willConnect(CayenneDataObject.java:340)
         at org.apache.cayenne.CayenneDataObject.setToOneTarget(CayenneDataObject.java:290)
         at nl.huygensinstituut.bia.domain.auto._PersName.setPerson(_PersName.java:69)
         at nl.huygensinstituut.bia.PersonInfoPanel$2.onSubmit(PersonInfoPanel.java:102)
         at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1351)
         at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:810)
         at java.lang.reflect.Method.invoke(Method.java:616)
         at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183)
         at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
         at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91)
         at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1220)
         at org.apache.wicket.RequestCycle.step(RequestCycle.java:1297)
         at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1399)
         at org.apache.wicket.RequestCycle.request(RequestCycle.java:529)
         at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:356)
         at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:201)
    (jetty frames snipped)

    Here's a snippet of the failing code:

        DataContext mycontext = Databinder.getContext();
        person = ObjectFactory.getInstance().getPerson(parameters.getInt("personid"),
    mycontext);
    // ObjectFactory is a singleton. getPerson method executes
    DataObjectUtils.objectForPK(context, Person.class, id);

        final PersName nameObj = (PersName) persNameForm.getModelObject();
    // PersName extends CayenneDataObject
        persNameForm.add(new Button("submitpersname", new ResourceModel("Save")) {
         ..verride
          public void onSubmit() {

            if (nameObj.getPerson() == null && person == null) {
              final Person auxiliary = ObjectFactory.getInstance().createPerson();
              auxiliary.setSex(Person.SEX_UNKNOWN);
              nameObj.setPerson(auxiliary);
            } else {
              nameObj.setPerson(person); // <-- line 102 where the
    exception is triggered. 'person'
            }
            super.onSubmit();
          }
        });

    Thanks for any advice!

    -- 
    Reinout van Schouwen
    http://vanschouwen.info/
    



    This archive was generated by hypermail 2.0.0 : Wed Jul 22 2009 - 06:34:50 EDT