Skip to content
Advertisement

JOOQ MySQL DATETIME Type

I’m trying to generate this simple SQL with JOOQ and for some reason I can’t get it done. I want the following code to be generated for MySQL databases.

CREATE TABLE T (
    F DATETIME
);

I expected it to be something like

dsl.createTable(name("T"))
   .column("F", MySQLDataType.DATETIME);

Unfortunately, MySQLDataType is deprecated. JOOQ explicitly says to only use types declared in SQLDataType, but for some reason I can’t find any.

I’ve already tried with DATE, LOCALDATE, LOCALDATETIME but all of them generate a TIMESTAMP field.


I’m using JOOQ to generate DDL for MySQL and Oracle DBMS’ at the same time. Oracle types are generated fine (I get DATE and it’s all right) but MySQL only gives me TIMESTAMPs.

Any hints?

Advertisement

Answer

The dialect specific data types were deprecated with #7375 in jOOQ 3.11, unfortunately without replacement functionality yet. The replacement will be implemented no earlier than jOOQ 3.13 (maybe later) through #5713, a much more powerful, dynamic data type registry – as opposed to the current static one, which depends completely on internal API and static initialisation.

For the time being, you can continue using MySQLDataType.DATETIME in your case, or create your own DefaultDataType instance for it. The two approaches are equally unsafe, one being deprecated, the other relying on internal API.

The deprecated types will not be removed for quite a while, though, for backwards compatibility reasons.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement