update linked objects

From: ti..e7en.ru
Date: Wed Dec 11 2002 - 07:00:07 EST

  • Next message: Craig Miskell: "Re: update linked objects"

    Hello cayenne-user,

    I have two linked tables
    CmList(id,title) and CmEmail(id,email,list_id)

    When I add to an existing CmList new CmEmail, and then I make commit
    addition does not occur.

    ... CmList mlist defined above ...
    addEmail(mlist);
    updateList(mlist);

    and nothing happens :-(((

    void addEmail(CmList mlist) {
       // new email object
       CmEmail email = (CmEmail)mlist.getDataContext().createAndRegisterNewObject("CmEmail");
       // or CmEmail email = (CmEmail)ctxt.createAndRegisterNewObject("CmEmail");
       // make link to list
       mlist.addToEmails(email);
    }

    void updateList(CmList mlist) {
      // ctxt defined above
      //check if it is a Transient object!!!
      if(mlist.getPersistenceState() == PersistenceState.TRANSIENT){
        System.out.println(">>>>>>>>>>>>>>>>>>>> register transient maillist:"+mlist);
        //register transient object
        ctxt.registerNewObject(mlist, "CmMaillist");
        System.out.println(">>>>>>>>>>>>>>>>>>>> commiting transient maillist:"+mlist);
        ctxt.commitChanges();
      }
      //check whether modified
      if(mlist.getPersistenceState() == PersistenceState.MODIFIED){
        System.out.println(">>>>>>>>>>>>>>>>>>>> commiting modified maillist:"+mlist);
        //commit it
        mlist.getDataContext().commitChanges();
      }
      //check whether new
      if(mlist.getPersistenceState() == PersistenceState.NEW){
        System.out.println(">>>>>>>>>>>>>>>>>>>> commiting new maillist:"+mlist);
        //commit it
        mlist.getDataContext().commitChanges();
      }
    }

    -- 
    Best regards, tim                          mailto:ti..e7en.ru
    



    This archive was generated by hypermail 2.0.0 : Wed Dec 11 2002 - 07:01:58 EST