Calling rollbackChanges will lost all changes, and create a new context and 
start over is complex  with many and variables changes to replicate in the new 
context...
I think the problem is that sync with db state is lost if the dataobjects are 
market commited before the real transaction commits, in fact, this what the 
code in ObjectStore that change the persistentceState:
     * Internal unsynchronized method to process objects state after commit.
     * 
     * @since 1.2
     */
    void postprocessAfterCommit(GraphDiff parentChanges) {
but that is not true, because transaction commits happen after this code runs 
no before as implied.

 I am considering some hacking along the lines:
1. Allow Transaction to execute arbitrary code after commit.2. ObjectStore now 
should register with current transaction to run postprocessAfterCommit after 
the transaction commits;
Well this is the idea, but I need more guide to do this, maybe not the right 
classes to hack o derive, how to install my changes in a modular way, etc., I 
am really new to cayenne. 
 Atte. Juan Manuel Díaz Lara 

    On Monday, April 11, 2016 11:04 AM, John Huss <johnth...@gmail.com> wrote:
 

 Try calling context.rollbackChanges() or just create a new context and
start over.

On Mon, Apr 11, 2016 at 10:31 AM Juan Manuel Diaz Lara
<jmdia...@yahoo.com.invalid> wrote:

>
>
> I am using 4.0.M3.
> I used the following solution, but the problem is that after
> commitChanges() the dataobjetcs are set to PersistenceState.COMMITED, if
> the stored procedure fails Cayenne does a DB rollback (that's ok), but
> dataobjects stay COMMITED, so I can not retry the this transaction after
> errors are solved.
> Is there any way to revert the persistenceState to their values before
> commitChanges if I detect the stored procedure failed ?
>
>            cayenneRuntime.performInTransaction(new
> TransactionalOperation<Integer>()
>                    {
>
>                        @Override
>                        public Integer perform() {
>                            context.commitChanges();
>                            //...
>                            SQLTemplate s = new SQLTemplate("SELECT
> pkg_inventario_fisico.apply( #bind($idAlmacen, 'VARCHAR')) AS id", true);
>                            s.setParamsArray(a);
>                            @SuppressWarnings("unchecked")
>                            List<DataRow> rows =
> CayenneDao.instance.context.performQuery(s);
>                            DataRow row = rows.get(0);
>                            //...
>                            return null;
>                        }
>
>                    }
>            );
>  Atte. Juan Manuel Díaz Lara
>
>    On Monday, April 11, 2016 10:06 AM, Mike Kienenberger <
> mkien...@gmail.com> wrote:
>
>
>  See the bottom part of this page starting at "In the second scenario":
>
>
> https://cayenne.apache.org/docs/4.0/cayenne-guide/persistent-objects-objectcontext.html#transactions
>
>
> On Mon, Apr 11, 2016 at 10:54 AM, Juan Manuel Diaz Lara
> <jmdia...@yahoo.com.invalid> wrote:
> >
> >
> >  I have a dataobjet graph with some changes, and a db stored procedure
> that should run after this changes are in the db, but must run in the same
> transaction because it make some more changes to other data, this changes
> can fail so I want the commitChanges fail if the stored procedure fails.
> >  Atte. Juan Manuel Díaz Lara
> >
> >
> >
> >
>
>

  

Reply via email to