kotlingenerator: key() - questionable signature

9 views
Skip to first unread message

David Karlsen

unread,
Nov 9, 2020, 11:06:00 AM11/9/20
to jooq...@googlegroups.com
The generated code looks like:

// -------------------------------------------------------------------------
// Primary key information
// -------------------------------------------------------------------------

override fun key(): Record2<String?, String?> = super.key() as Record2<String?, String?>

but I guess it should be Record2<String,String> since no part of the key should be allowed to be null for a pk?

Using 3.14.2


Lukas Eder

unread,
Nov 9, 2020, 11:20:11 AM11/9/20
to jOOQ User Group
Hi David,

Thanks for your message.

Some RDBMS support nullable primary keys. Others support deferred constraints (which jOOQ is currently unaware of), and even if both things are not supported, there might still be an identity or a trigger-generated value in your primary key constraint, in case of which it is not unreasonable to have null values prior to inserting a record. In addition to that, you could be left-joining a table, and its primary key column values would be null for this result set, despite them not being null in the database. This is no different from what we've discussed before on this list:

I'm aware that we might be discussing an 80/20 situation here. In 80% (or even more) of the cases, what you're expecting is reasonable, and you're willing to risk running into NPEs in those 20% of the cases I've mentioned above (or even less). We will be offering additional flags in the code generator, which allow you to override this behaviour in the future:

But for now, the correct way is the only way.

Thanks,
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/CAGO7Ob1OQ6Q0x4B1cRxYRQ2oVcjptrKTXPcd35T6RNXdFvrvYg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages