Hello,

Thank you very much for your message. This is a very recurring theme on
this mailing list, on github, and on Stack Overflow. I have written a blog
post explaining jOOQ's assumptions and current behaviour:
https://blog.jooq.org/2018/11/05/how-to-use-jooqs-updatablerecord-for-crud-to-apply-a-delta/

TL;DR: Given your intermediary data type Author that is a POJO with no way
of distinguishing between null (the value) and null (the default), the only
reasonable thing jOOQ can assume on your session.newRecord(AUTHOR, author)
call is for you to want to explicitly set all null values (how else would
you set null values, otherwise?)

There are a few workarounds as documented in the above blog post.

I have also added a feature request to allow for loading the JSON document
directly into the record, which is probably what a lot of jOOQ users would
want to do. The feature request is here:
https://github.com/jOOQ/jOOQ/issues/8016

The intermediary POJO is not really of any value in your described
use-case. The other option would be to create a POJO containing only id and
firstname attributes, which would more closely resemble your specific data
structure. Or a Map.

I hope this helps,
Lukas

On Sun, Nov 4, 2018 at 6:12 PM 'Maverick Skywalker' via jOOQ User Group <
[email protected]> wrote:

> I want to use JavaScrip GUI API who only send me the attributes they have
> changed inside the object. So I get an object with many null values inside
> the attributes and when I run an ordinary update command, jOOQ will null
> all existing attributes inside the database. Is there an option where the
> jOOQ CRUD update command generates only updates for not null values?
>
> *SQL Table before jOOQ update*
> Author
> Id | Firstname| Lastname
> 1 | Rudi| Schürle
>
> *json update request*
>
>
>
>
>
>
> *{  Author:   {    id:1,    firstname="Rudolf"  }}*
>
> *Code*
> Author author = gson.fromJson(jsonElement, Author.class); // gson set
> Lastname to null
>
> AuthorRecord updateRecord = session.newRecord(AUTHOR,author);
> updateRecord.update(); //Lastname with null value will persist inside the
> database
>
> *SQL Table after jOOQ update << Issue*
> Author
> Id | Firstname| Lastname
> 1 | Rudolf | null
>
> --
> 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