Re: Problems with CommitChanges and object PersistenceState

From: laila paganelli (laila.paganell..mail.com)
Date: Fri Jan 28 2005 - 03:52:37 EST

  • Next message: moraru dragos: "do i need datacontext synchronization?"

    The context used is the same everywhere.
    This is the correct code example, where I add a System.out.println
    after the first commit

       context = org.objectstyle.cayenne.access.DataContext.createDataContext();
       prn = (PendingRawNews)context.createAndRegisterNewObject(PendingRawNews.class);
       context.commitChanges();
       System.out.println(context.newObjects());

       // ..... create other objects in the same context

       context.commitChanges();

    This is the output of the println

    [{
      [insertionDate => Fri Jan 28 09:43:29 CET 2005]
      <oid: com.extrapola.scooter.dataModel.PendingRawNews: <ID: 982>; state: new>
    }]

    I'm using cayenne 1.1rc2

    Thank's
    Laila

    On Thu, 27 Jan 2005 23:38:51 -0500, Andrus Adamchik
    <andru..bjectstyle.org> wrote:
    >
    > On Jan 27, 2005, at 7:48 AM, laila paganelli wrote:
    >
    > > context =
    > > org.objectstyle.cayenne.access.DataContext.createDataContext();
    > > prn =
    > > (PendingRawNews)this.dataContext().createAndRegisterNewObject(PendingRa
    > > wNews.class);
    >
    >
    > > After the first commit the object prn is saved on the database,
    > > but the state is still PersistenceState.NEW, while I expect it to be
    > > PersistenceState.COMMITTED.
    > > After the second commit I find one more prn object on database.
    > > Why? What is wrong?
    >
    > Is it possible that "context" in the first line and
    > "this.dataContext()" on the second are two different objects? Try
    > rewriting the code to make sure the same context is used everywhere.
    > E.g.:
    >
    > context = DataContext.createDataContext();
    > prn = (PendingRawNews)
    > context.createAndRegisterNewObject(PendingRawNews.class);
    >
    > Cheers,
    > Andrus
    >
    >



    This archive was generated by hypermail 2.0.0 : Fri Jan 28 2005 - 03:52:38 EST