Hello,

This question keeps popping up on the list and elsewhere, and I always have
the same counter question. If you need optimistic locking, then why not
just use the record all the way to help you keep track of the internal
flags? What are you gaining from using the POJO intermediary? Sure, you can
prevent the dependency on jOOQ where you might prefer not to have such a
dependency, i.e. the UI.

But since you want optimistic locking to apply, you have an implicit
dependency anyway, so why not just use the Record?

If using the POJO is imperative, then yes, your code is one reasonable way
to transfer information back to the record.

Regarding your question about adding more logic to your POJOs, you can
extend the JavaGenerator to generate "custom code sections" for you, in any
generated artefact:
https://www.jooq.org/doc/latest/manual/code-generation/codegen-custom-code

You can also completely override the generation of POJOs in JavaGenerator
and generate whatever you need inside of them.
Hope this helps,
Lukas

2018-03-26 13:45 GMT+02:00 BTJ <[email protected]>:

> Ok, I came up with this code but not sure if this is the best way?
>
> PersonRecord personRecord = dsl.newRecord(Tables.PERSON, person);
> if (person.getId() != null) {
>     personRecord.changed(Tables.PERSON.ID, false);
>     personRecord.changed(Tables.PERSON.VERSION, false);
> }
> personRecord.store();
>
>
>
> On Monday, March 26, 2018 at 11:46:58 AM UTC+2, BTJ wrote:
>>
>> I am back to JOOQ after I used JOOQ for as project some years ago but
>> there is one thing that is not clear to me.
>> When fetching a POJO and updating this object, what is the best way to
>> update the record in the database?
>> I see I have been using the dsl.executeUpdate method but I am trying to
>> use ExecuteWithOptimisticLocking and I loose this feature when using this
>> method.
>> So how should I move from POJO to records to use the store method? Or is
>> it another way to do this?
>>
>> Also, a bit on the sideline. If I need more functionality in my POJOs,
>> what's the best way to "generate" POJOs? Just copy the field names from the
>> record object and create my own POJOs or?
>>
>>
>> Regards,
>>
>> BTJ
>>
> --
> 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