简体   繁体   English

EclipseLink DDL用小数秒创建MySql DATETIME

[英]EclipseLink DDL creating MySql DATETIME with fractional seconds

I am using EclipseLink 2.6.0 in my project together with MySQL 5.6.19 . 我在项目MySQL 5.6.19 EclipseLink 2.6.0MySQL 5.6.19一起使用。

Since mysql 5.6.4 supports a fieldtype DATETIME(6) which allows to store a date with milliseconds precision in its value. 由于mysql 5.6.4支持字段类型DATETIME(6) ,因此它允许以毫秒精度存储日期值。 Also EclipseLink 2.6.0 says it supports this functionality. EclipseLink 2.6.0表示它支持此功能。


I am creating a database from my entities . 我正在根据我的实体创建数据库 And I am not able to force it to create a proper field. 而且我不能强迫它创建一个合适的领域。 In logs, during database creation I constantly see: 在日志中,在数据库创建期间,我经常看到:

CREATE TABLE MY_TABLE (..., DATE_FIELD DATETIME ...)

when, obviously, what I want is: 显然,什么时候我想要的是:

CREATE TABLE MY_TABLE (..., DATE_FIELD DATETIME(6), ...)

I tried using both, simple and annotated version: 我尝试同时使用简单版本和带注释版本:

private java.util.Date date1;

@Temporal(value = TemporalType.TIMESTAMP)
private java.util.Date date2;

but the outcome is always the same. 但是结果总是一样的。 So how does the Eclipselink supports this? 那么Eclipselink如何支持这一点? How to determine the proper field type? 如何确定正确的字段类型?

Thanks specializt for the tip, easy solution: 感谢specializt提供的提示,简单的解决方案:

@Column(length=6)
private Date myTime;

works also with YodaTime converter ( description ) 也可与YodaTime转换器一起使用( 描述

@Column(length=6)
@Converter(name = "dateTimeConverter", converterClass = pl.ds.eemediation.storage.entities.converters.JodaDateTimeConverter.class)
@Convert("dateTimeConverter")
private DateTime date;

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

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