简体   繁体   English

JOOQ MySQL 日期时间类型

[英]JOOQ MySQL DATETIME Type

I'm trying to generate this simple SQL with JOOQ and for some reason I can't get it done.我正在尝试使用 JOOQ 生成这个简单的 SQL,但由于某种原因我无法完成。 I want the following code to be generated for MySQL databases.我希望为 MySQL 数据库生成以下代码。

CREATE TABLE T (
    F DATETIME
);

I expected it to be something like我希望它是这样的

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

Unfortunately, MySQLDataType is deprecated.不幸的是,不推荐使用MySQLDataType JOOQ explicitly says to only use types declared in SQLDataType , but for some reason I can't find any. JOOQ 明确表示只使用在SQLDataType声明的SQLDataType ,但由于某种原因我找不到任何类型。

I've already tried with DATE , LOCALDATE , LOCALDATETIME but all of them generate a TIMESTAMP field.我已经尝试过DATELOCALDATELOCALDATETIME但它们都生成了一个TIMESTAMP字段。


I'm using JOOQ to generate DDL for MySQL and Oracle DBMS' at the same time.我正在使用 JOOQ 同时为 MySQL 和 Oracle DBMS 生成 DDL。 Oracle types are generated fine (I get DATE and it's all right) but MySQL only gives me TIMESTAMP s. Oracle 类型生成得很好(我得到DATE并且没关系)但 MySQL 只给我TIMESTAMP s。

Any hints?任何提示?

The dialect specific data types were deprecated with #7375 in jOOQ 3.11, unfortunately without replacement functionality yet.方言特定数据类型在 jOOQ 3.11 中被#7375弃用,不幸的是还没有替换功能。 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.替换将不早于 jOOQ 3.13(可能更晚)通过#5713 实现,这是一个更强大的动态数据类型注册表 - 与当前的静态注册表相反,后者完全取决于内部 API 和静态初始化。

For the time being, you can continue using MySQLDataType.DATETIME in your case, or create your own DefaultDataType instance for it.目前,您可以在您的情况下继续使用MySQLDataType.DATETIME ,或为其创建您自己的DefaultDataType实例。 The two approaches are equally unsafe, one being deprecated, the other relying on internal API.这两种方法同样不安全,一种被弃用,另一种依赖于内部 API。

The deprecated types will not be removed for quite a while, though, for backwards compatibility reasons.但是,出于向后兼容性的原因,弃用的类型在很长一段时间内都不会被删除。

You could use the corresponding SQLDataType instead.您可以改用相应的 SQLDataType。 link: official api链接: 官方api

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

To force timestamp usage强制使用时间戳

jooq manual 乔克手册

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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