Thanks for your patience. I've had a look at this issue and created a
ticket here with some more details:
https://github.com/jOOQ/jOOQ/issues/15115

I don't think jOOQ can do much about this case. jOOQ doesn't know which
fields you've changed in your POJO (rental.setRentalDate()) and which
fields have been changed in the database, because unlike the
UpdatableRecord, the POJO doesn't keep any dirty flags. That's the point of
the POJO types. However, there might be an argument in favour of ignoring
the optimistic locking feature when:

- An UpdatableRecord was not "fetched" (i.e. created entirely in the
client, e.g. from a POJO as in your case)
- When we're using unversioned optimistic locking (because with versioned
rows, this problem wouldn't happen)

Thoughts?

On Wed, May 17, 2023 at 5:27 PM Lukas Eder <[email protected]> wrote:

> Thanks, I will, soon
>
> On Wed, May 17, 2023 at 5:06 PM Simon Martinelli <
> [email protected]> wrote:
>
>> I didn't configure any column so it should use all columns.
>>
>> You can try it yourself: https://github.com/simasch/jooq-workshop
>> (Make sure Docker is running locally)
>>
>> That's the test that causes the problem:
>>
>> https://github.com/simasch/jooq-workshop/blob/main/jooq-sakila/src/test/java/ch/martinelli/edu/jooq/sakila/exercise/Ex06DaosTest.java
>>
>> On Wednesday, May 17, 2023 at 4:53:50 PM UTC+2 [email protected] wrote:
>>
>>> Hi Simon,
>>>
>>> What column(s) did you configure for your optimistic locking checks?
>>> What SQL queries are being generated in your debug logs?
>>>
>>> Best Regards,
>>> Lukas
>>>
>>> On Wed, May 17, 2023 at 4:39 PM Simon Martinelli <[email protected]>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> I've configured optimistic locking:
>>>>
>>>> @Configuration
>>>> public class SakilaJooqConfiguration {
>>>>
>>>> @Bean
>>>> public DefaultConfigurationCustomizer configurationCustomizer() {
>>>>     return (DefaultConfiguration c) -> c.settings()
>>>>         .withExecuteWithOptimisticLocking(true);
>>>>     }
>>>> }
>>>>
>>>> Now I try to use a DAO with a POJO to read and update:
>>>>
>>>> var rentalDao = new RentalDao(dsl.configuration());
>>>>
>>>> rentalDao.findOptionalById(854L).ifPresent(rental -> {
>>>>     rental.setRentalDate(LocalDateTime.now());
>>>>     rentalDao.update(rental);
>>>> });
>>>>
>>>> But this leads to
>>>>
>>>>
>>>> org.jooq.exception.DataChangedException: Database record has been
>>>> changed
>>>>
>>>> at
>>>> org.jooq.impl.UpdatableRecordImpl.checkIfChanged(UpdatableRecordImpl.java:507)
>>>> at
>>>> org.jooq.impl.UpdatableRecordImpl.storeMergeOrUpdate0(UpdatableRecordImpl.java:345)
>>>> at
>>>> org.jooq.impl.UpdatableRecordImpl.storeUpdate0(UpdatableRecordImpl.java:240)
>>>> at
>>>> org.jooq.impl.UpdatableRecordImpl.lambda$storeUpdate$1(UpdatableRecordImpl.java:232)
>>>> at org.jooq.impl.RecordDelegate.operate(RecordDelegate.java:144)
>>>> at
>>>> org.jooq.impl.UpdatableRecordImpl.storeUpdate(UpdatableRecordImpl.java:231)
>>>> at
>>>> org.jooq.impl.UpdatableRecordImpl.update(UpdatableRecordImpl.java:168)
>>>> at
>>>> org.jooq.impl.UpdatableRecordImpl.update(UpdatableRecordImpl.java:163)
>>>> at org.jooq.impl.DAOImpl.update(DAOImpl.java:210)
>>>> at org.jooq.impl.DAOImpl.update(DAOImpl.java:186)
>>>>
>>>> When I debug into UpdatableRecordImpl I see that in the record only the
>>>> id is set.
>>>>
>>>> Is this a bug or did I miss somehting?
>>>>
>>>> Thanks,
>>>> Simon
>>>>
>>>> --
>>>> 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].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/jooq-user/b734e1bf-0121-47a2-be39-196b0cd8b1e5n%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/jooq-user/b734e1bf-0121-47a2-be39-196b0cd8b1e5n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>> 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].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/jooq-user/e5aca150-0b82-4618-8de9-d8d50092742fn%40googlegroups.com
>> <https://groups.google.com/d/msgid/jooq-user/e5aca150-0b82-4618-8de9-d8d50092742fn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/CAB4ELO7s7CMOrz7rXEVk9X5t2Z-LQ2ZegrgsRNdsBrGTpyAZ2A%40mail.gmail.com.

Reply via email to