Hello,

A similar problem has been reported before:
https://groups.google.com/forum/#!topic/jooq-user/_cp2-mrtZ7k/discussion.

It has lead to this feature requests (among others):
- https://github.com/jOOQ/jOOQ/issues/2700
- https://github.com/jOOQ/jOOQ/issues/2702

With jOOQ 3.2, #2702 has now been implemented and the jOOQ runtime is aware
of nullable and defaulted columns, although this information is not yet
used. In the future, there might be a change in how jOOQ deals with "NOT
NULL DEFAULT" columns from UpdatableRecords, when they're set to NULL, i.e.
when a Java NULL value clearly means that it is undefined.

In the mean time, your workaround is one way to do this, another would be
this:

      final Record inputRec = sql.newRecord(USER);
      inputRec.from(user);
      for (Field<?> f : inputRec.fields()) {
          if (inputRec.getValue(f) == null)
              inputRec.changed(false);
      }
      inputRec.store();

Let me know if this helps,

Cheers
Lukas

2013/10/16 Marko Topolnik <[email protected]>

> This is the code I have come up with (the variable *user* holds the POJO
> with the request data):
>
>       final Record inputRec = sql.newRecord(USER);
>       inputRec.from(user);
>       final List<Field<?>> fields = new ArrayList<>();
>       final List<Object> values = new ArrayList<>();
>       for (Field<?> f : inputRec.fields()) {
>           final Object v = inputRec.getValue(f);
>           if (v != null) { fields.add(f); values.add(v); }
>       }
>       sql.insertInto(u, fields).values(values).execute();
>
> Please let me know if there's a cleaner/shorter approach.
>
> -- Marko
>
> --
> 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/groups/opt_out.
>

-- 
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/groups/opt_out.

Reply via email to