Thank you very much for reporting this and for the detailed test cases.

Unfortunately, these batch calls currently do not respect the optimistic
locking semantics they should as is documented in this issue here:
https://github.com/jOOQ/jOOQ/issues/1637

The only workaround right now is not to use batching for these records.

Hope this helps,
Lukas

2017-03-31 17:30 GMT+01:00 <[email protected]>:

> When I try to do a batch update on a stale record it fails and does not
> throw any kind of exception. For example:
>
> RoleRecord roleRecord = new RoleRecord();
> roleRecord.setName("role"); // name is the PK for this table
>
>
> roleRecord.attach(configuration);
> roleRecord.insert();
>
> assertThat(roleRecord.getVersion()).isEqualTo(1);
> assertThat(roleRecord.getDescription()).isNull();
>
> roleRecord.setDescription("desc1");
> DSL.using(configuration).batchUpdate(roleRecord).execute(); // this works 
> fine as we have the most current roleRecord
>
> RoleRecord fromDB = 
> DSL.using(configuration).selectFrom(ROLE).where(ROLE.NAME.eq("role")).fetchOne();
>
> assertThat(fromDB.getDescription()).isEqualTo("desc1");
> assertThat(fromDB.getVersion()).isEqualTo(2);
>
> roleRecord.setDescription("desc2");
> DSL.using(configuration).batchUpdate(roleRecord).execute(); // does not throw 
> DataChangedException, we have a stale roleRecord here
> //roleRecord.update(); // throws a DataChangedException which is the correct 
> behaviour
>
> fromDB = 
> DSL.using(configuration).selectFrom(ROLE).where(ROLE.NAME.eq("role")).fetchOne();
>
> assertThat(fromDB.getVersion()).isEqualTo(3); // fails
> assertThat(fromDB.getDescription()).isEqualTo("desc2"); // fails
>
> --
> 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.
>

-- 
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