Just upgraded from 3.7.3 to 3.8.0 and running into the following situation 
using optimistic locking. Other version details: Java 8, PostgreSQL 9.5.x

We've got a DSLContext with a config that 
has withExecuteWithOptimisticLocking set to true and we are using a 
rec_version integer field on our table. For our test, we fetch two of the 
same record (same primary key), then change a value on record1, perform an 
update, then change a different value on record 2, perform an update. Under 
3.7.3 this works as expected -- the second update on record 2 fails with a 
DataAccessException. Under 3.8.0, however, even though the second update 
technically fails (no modification is made to the database, updated rows is 
0, etc)  jOOQ does not throw a DataAccessException and in fact appears to 
treat the update as successful.

Tracing through it, here are a few more details on what is going on:

When record update() is invoked the following new logic is performed 
(UpdateRecordImpl):

line 251, setReturningIfNeeded is called, which sets the returning value to 
be table.id
line 252, int result = update.execute(); 
line 253, checkIfChanged(result, version, timestamp);


If you trace the update.execute() call down, eventually you hit an 
execute() method in AbstractDMLQuery:

line 325 has this conditional:

        if (returning.isEmpty()) {
            return super.execute(ctx, listener);
        }

Under jOOQ 3.7.3, returning is in fact empty, so return super.execute(ctx, 
listener); is what is invoked here.

But under 3.8.0 we hit the else case which sets result to 1:

int result = 1;

And then switches on the database type, for Posgres we have:

                case POSTGRES: {
                    listener.executeStart(ctx);
                    rs = ctx.statement().executeQuery();
                    listener.executeEnd(ctx);
                    break;
                }

The statement has in fact been executed (and updated 0 rows), but result is 
still 1, so if we jump back to UpdateRecordImpl:

line 252, int result = update.execute(); // result is 1 here (even though 
query didn't update anything..)
line 253, checkIfChanged(result, version, timestamp); 

The checkIfChanged() call is going to fail in this case (fail in that it 
doesn't throw a DataAccessException.).

Hopefully that is enough detail to understand the problem. Is this a bug? 
It sure seems like it. But let me know if there is some configuration issue 
or some misunderstanding on my part.

Cheers,
Kai





-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to