0

I am using EclipseLink 2.6.0 in my project together with MySQL 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. Also EclipseLink 2.6.0 says it supports this functionality.


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? How to determine the proper field type?

Atais
  • 10,857
  • 6
  • 71
  • 111
  • 1
    have you seen/tried using @Column(columnDefinition="DATETIME(6)") ? – Chris Sep 30 '15 at 00:20
  • well.. that works as expected. I know the annotation, I do not know why I did not think about it :-) Thanks. – Atais Sep 30 '15 at 08:04
  • 2
    using `columnDefinition` breaks portability and always is the worst possible approach - your **actual** solution **should** be `@Column(length=6)` – specializt Sep 30 '15 at 08:25
  • @specializt you can provide this as a full answer if you like. It works just the same for now, but I understand the difference. – Atais Sep 30 '15 at 08:28

1 Answers1

0

Thanks specializt for the tip, easy solution:

@Column(length=6)
private Date myTime;

works also with YodaTime converter (description)

@Column(length=6)
@Converter(name = "dateTimeConverter", converterClass = pl.ds.eemediation.storage.entities.converters.JodaDateTimeConverter.class)
@Convert("dateTimeConverter")
private DateTime date;
Community
  • 1
  • 1
Atais
  • 10,857
  • 6
  • 71
  • 111