Re: Newbie: DataObject declaration and commit

From: Andrea Borgogelli Avveduti (borgogell..otmail.com)
Date: Fri Dec 16 2005 - 03:46:55 EST

  • Next message: Andrus Adamchik: "Re: Newbie: DataObject declaration and commit"

    Hi Andrus,
    I was wondering if dataobjects which are not register are comitted too.
    In the following example I have declared two dataobjects, set the relative attributes and resgistered only one. But when I commit, Cayenne inserts two objects in my db.

    // Example (not real code):

    .....
    public MyCayenneDataClass myCayenneDataObject;
    .....

    myCayenneDataObject.setMyAttribute(foo);

    ......
    MyCayenneDataClass myCayenneDataObject2 = ( MyCayenneDataClass )  
    dataContext.createAndRegisterNewObject( MyCayenneDataClass.class );
    .....
    datacontext.commitChanges(); // TWO OBJECTS ARE COMMITTED. WHY NOT ONLY ONE ?



    From:  Andrus Adamchik <andru..bjectstyle.org>
    Reply-To:  cayenne-user@objectstyle.org
    To:  cayenne-user@objectstyle.org
    Subject:  Re: Newbie: DataObject declaration and commit
    Date:  Thu, 15 Dec 2005 19:38:17 +0300
    >>So what's the difference between the two object decalrations ?
    >
    >Andrea, it is not clear from your example how the first object is  
    >initialized and later manipulated. This advice is a shot in the
    >dark,  but one way to keep a transient object around is to create
    >and  register an object, and then delete it from DataContext right
    >before  the commit.
    >
    >Andrus
    >
    >
    >On Dec 15, 2005, at 4:23 PM, Andrea Borgogelli Avveduti wrote:
    >>// Example (not real code):
    >>
    >>.....
    >>public MyCayenneDataClass myCayenneDataObject;
    >>.....
    >>MyCayenneDataClass myCayenneDataObject2= ( MyCayenneDataClass )  
    >>dataContext.createAndRegisterNewObject( MyCayenneDataClass.class );
    >>.....
    >>datacontext.commitChanges();
    >>
    >>
    >>// Question is:
    >>
    >>/*
    >>
    >>Why the Cayenne try to insert to records in the DB. I don't want to
    >>  insert myCayenneDataObject but only myCayenneDataObject2. I'd
    >>like  to use the first object only for temporary data.
    >>So what's the difference between the two object decalrations ?
    >>
    >>Thank you all for any help
    >>
    >>Andrea.
    >>
    >>*/
    >



    This archive was generated by hypermail 2.0.0 : Fri Dec 16 2005 - 03:46:56 EST