theUnicycleGuy
theUnicycleGuy

Reputation: 145

How to Initialize a custom row type Jooq Record

Similar to this question: How to initialise and create a ResultSet and Record in Jooq? but with a custom row type record rather than a simple table record. I am instantiating a jooq record to use in mocking, but the record has more than 22 columns and contains rows from many joined tables, so I am using RecordImpl.

RecordImpl r1 = new RecordImpl();
r1.set(COURSE.ID.as("course_id"), 1);

This throws exception

java.lang.IllegalArgumentException: Field ("course_id") is not contained in Row ()

Note I am not using RecordImpl directly since it is package private, so I use a

public class RecordWrapper extends RecordImpl {}

How can I set fields directly on an untyped Jooq record?

Upvotes: 1

Views: 2002

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 221145

You shouldn't instanciate or extend RecordImpl which is part of jOOQ's internal API. Instead, use DSLContext.newRecord(), e.g.

Record1<Integer> r1 = ctx.newRecord(COURSE.ID.as("course_id")).values(1);

Upvotes: 0

Related Questions