When generating JOOQ classes via JOOQ code gen, for each field, there will be a SQLDataType associated with it like below.
public final TableField<EventsRecord, LocalDateTime> CREATED_AT = createField(DSL.name("CREATED_AT"), SQLDataType.LOCALDATETIME(6).nullable(false), this, "");
What's the usage or purpose to have SQLDataType with each generated field? Since we already have a return type and client code is likely to use the this type to do the compile check.
Why we still need to know the actual SQLDataType in generated class/fields?
By client type, you probably mean the LocalDateTime
type, i.e. the <T>
type that you will find throughout the jOOQ API. Sure, that's the type you care about, but jOOQ, internally, will care about the org.jooq.DataType
instead. Your example already gives away two ideas why this may be useful:
LOCALDATETIME(6)
, which is used (among other things):
CAST
expressions. Try DSL.cast(inline("2000-01-01 00:00:00"), EVENTS.CREATED_AT)
,DSLContext.meta(EVENTS)
. You should see a CREATE TABLE
statement with the appropriate data typeINNER JOIN
or a LEFT JOIN
DataType
can have, which would be interesting for jOOQ at runtime including:
String
is not a String
. For example, it could mean CHAR(2)
, CHAR(5)
, VARCHAR(100)
, CLOB
, which are all quite different things in some dialects.It would be a shame if your runtime meta model didn't have this information available.