Hibernate 5.1 and Java 8 LocalDateTime

I switched to Java 8 and Hibernate 5 to solve the problem of the inability to store milliseconds in Hibernate.

private LocalDateTime date = LocalDateTime.now();

public LocalDateTime getDate() {
    return date;
}

Maven Dependencies

  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.0.1.Final</version>
  </dependency> 

  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-java8</artifactId>
    <version>5.0.1.Final</version>
  </dependency>

Although this Hibernate still saves the LocalDateTime object as tinyblob. What am I missing? I am using MySQL 5.6.19

According to this Hibernate Issue , the hibernate-java8 module should map this to TIMESTAMP. I tried to place @Column(columnDefinition="TIMESTAMP)on the receiver, but this led to a DataIntegrityViolationException.

Placed @Type(type="org.hibernate.type.LocalDateTimeType")on a getter. The database table is still saved as tinyblob.

+4
source share
3

:

  • Hibernate 5.2.10. Final
  • hibernate-java8 , hibernate-core

Hibernate / JDK:

  • OffsetDateTime @Type(type= "org.hibernate.type.OffsetDateTimeType")
  • LocalDateTime @Type(type= "org.hibernate.type.LocalDateTimeType")

... ...

+2

Mysql , , , blob.

0

, TINYBLOB, , JPA 2.1 Java 8, API Date Time .

, java.sql.Date java.sql.Timestamp .

0

Source: https://habr.com/ru/post/1608526/


All Articles