On Fri, Mar 29, 2019 at 8:36 AM Christian Master <[email protected]> wrote:

> Perfect, thank you. (to copy it from one db to another, create2 was
> missing....)
>

Yes of course.


> For one row i do it this way:
>     MyRecord my1 = create2.selectFrom(KTO).fetchAny();
>     my1.set(KTO.KTOID,null);
>     create1.insertInto(KTO).set(my1).execute();
>
> This works for some fields, but some are null. The ID gets generated, most
> of the data stored, but I dont understand why it works for some fields, and
> for some not.
> Is this wrong way to insert one Record from one DB to another? Or one
> Table to another?
>

In UpdatableRecord, the primary key value is "special". If you set it to
null on an existing record, the record is assumed to be a "copy" of the
previous one, because what else could a null primary key mean other than
the record needs to be inserted rather than updated. Because of this
assumption, setting a primary key to null also sets all the other column
changed flags to true, to enforce them being inserted, despite the fact
that you didn't actually change them explicitly.

With other values, setting them to null means you actually want the value
to be set to null. There's no reason for any further implicit behaviour. If
you want to make this more explicit, you could also write:

    MyRecord my1 = create2.selectFrom(KTO).fetchAny();
    my1.set(KTO.KTOID,null);
    my1.changed(true);
    my1.changed(KTO.KTOID, false);
    create1.insertInto(KTO).set(my1).execute();

That's what happens behind the scenes, implicitly.

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