Comparing composite primary keys
By definition, a composite primary key involves two or more columns that should uniquely identify a record. A composite primary key is usually a natural key (even if it is composed of references to surrogate keys) and can often be preferable to surrogate keys in relationship tables: https://blog.jooq.org/2019/03/26/the-cost-of-useless-surrogate-keys-in-relationship-tables/. This means that predicates based on composite keys must contain all the involved columns. For instance, the PRODUCTLINE
table has a composite key as (PRODUCT_LINE
, CODE
), and we can write a predicate for fetching a certain record by chaining the fields of the composite key via and()
, as follows:
var result = ctx.selectFrom(PRODUCTLINE) .where(PRODUCTLINE.PRODUCT_LINE.eq("Classic Cars") .and(PRODUCTLINE.CODE.eq(599302L))) .fetchSingle();
Alternatively, we can separate fields from values using row()
(the eq()
method doesn't require an explicit...