cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maik Musall <>
Subject Re: About Improved Transaction API on 4.0
Date Tue, 20 Mar 2018 16:07:00 GMT
First an additional answer: you can return whatever you want. That will then become the return
value of the performInTransaction() call.

But I have a related question. How is an explicit rollback supposed to work there? If I halfway
through decide to roll back the entire transaction, after a few commitChanges() already have
happened, how do I do that?

I tried


but then I get

java.lang.IllegalStateException: Transaction must have ‘STATUS_ACTIVE’ to be committed.

What seems to work is throwing a CayenneRuntimeException, but that will get rethrown after
the rollback, so I would have to catch that again outside the performInTransaction() call,
which doesn't feel how it's supposed to work.


> Am 20.03.2018 um 16:40 schrieb John Huss <>:
> performInTransaction just encapsulates a database transaction, so it has no
> affect on the object (ORM) level, it only affects what is visible in the
> database.  So the behavior with commitChanges() is the same as it would be
> outside a performInTransaction block.
> On Tue, Mar 20, 2018 at 10:25 AM Juan Manuel Diaz Lara
> <> wrote:
>>  runtime.performInTransaction(() -> {
>>        // ... do some changes
>>        context.commitChanges();
>>        // ... do more changes
>>        context.commitChanges();
>>        return true;
>> });   Previous code is an example on "Guide to 4.0 Features".
>> My questions are:
>>   - What is then persistence state of objects after first commitChanges()
>> ?
>>   - If second commitChanges()  fails, what happen to the persistence
>> state coming from firs commitChages() ?
>>   - What happen if we return false?
>> Atte. Juan Manuel Díaz Lara

View raw message