简体   繁体   中英

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 TIMESTAMP s.

Any hints?

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.

You could use the corresponding SQLDataType instead. link: official api

In jooq 3.13.2
<generator>
     <generate>
     <javaTimeTypes>false</javaTimeTypes>
     </generate>
...

To force timestamp usage

jooq manual

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM