Insert or Update with DAOs or records?

18 views
Skip to first unread message

Jacobo de Vera

unread,
Aug 15, 2016, 7:09:55 AM8/15/16
to jOOQ User Group
Hi,

I'm looking at a piece of code where we go from a generated POJO to a full insertInto query, where we manually specify all the POJO fields. This is done so we can do onDuplicateKeyIgnore on it.

The pain here is that when adding a new column to that table, one also has to add it to this query. I quickly set off to replace this with a DAO usage with the original POJO, but found no way to express the desire to ignore errors if the key already existed.

My question now is whether such mechanism exists or not.

Thanks and regards,

Jacobo de Vera

Lukas Eder

unread,
Aug 17, 2016, 8:15:37 AM8/17/16
to jooq...@googlegroups.com
Hi Jacobo,

Let me try to repeat this with other words, to see if I understood correctly. You have a POJO and want to insert it only if the corresponding primary key does not yet exist. So, you want to do something like:

ctx.insertInto(TABLE)
   .set(ctx.newRecord(TABLE, pojo))
   .onDuplicateKeyIgnore()
   .execute();

Does this already solve the problem?

Cheers,
Lukas

--
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 jooq-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jacobo de Vera

unread,
Aug 17, 2016, 10:20:57 AM8/17/16
to jOOQ User Group
That does solve the problem nicely. Thanks Lukas!
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages