我试图使用JOOQ向MySQL 8插入一行,其中包含即时的日期时间映射,但是
org.jooq.exception.DataAccessException
com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect datetime value: '2020-05-02 02:45:38.134463+00:00' for column 'created' at row 1
出于某种原因乔克补充道
+00:00
MySQL不支持to DATETIME列和该格式。
如果乔克能做到开箱即用,有什么想法吗?
CREATE TABLE `user` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`version` BIGINT NOT NULL DEFAULT 0,
`name` VARCHAR(255) NOT NULL,
`created` DATETIME NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `ind_name`(`name`)
);
@Getter
@Setter
public class User {
@NonNull
@Id
private Long id;
@NonNull
@Version
private Long version;
@NonNull
@Column(name = "name")
private String name;
@NonNull
@Column(name = "created")
private Instant created;
}
dslContext.insertInto( DSL.table( "user" ), field( "name", String.class ),
//or field( "created", Instant.class), the result is the same
field( "created", SQLDataType.INSTANT ) )
.values( name, Instant.now() )
.returningResult( DSL.asterisk() )
.fetchOne()
.into( User.class );