Hibernate 5.1和Java 8 LocalDateTime

I have switched to Java 8 and Hibernate 5 to overcome the problem of not being able to store milliseconds in Hibernate.

private LocalDateTime date = LocalDateTime.now();

public LocalDateTime getDate() {
return date;
}

Maven dependency


org.hibernate
hibernate-core
5.0.1.Final



org.hibernate
hibernate-java8
5.0.1.Final

Nevertheless, Hibernate still stores the LocalDateTime object as a tinyblob. What am I missing? I am using MySQL 5.6.19

According to this
Hibernate Issue, the hibernate-java8 module should map it to TIMESTAMP. I tried to put a @Column(columnDefinition=“TIMESTAMP”) on the getter, But this will cause DataIntegrityViolationException.

Put @Type(type=“org.hibernate.type.LocalDateTimeType”) on the getter. The database table remains as tinyblob.

As of this comment:

> Hibernate version is 5.2.10.Final
>Not recommended Using hibernate-java8, all functions are included in hibernate-core

Hibernate provides type converters for all JDK date/time types:

>The OffsetDateTime getter on the entity should use @ Type annotation (type = “org.hibernate.type.OffsetDateTimeType”)
>LocalDateTime getter on the entity should use @Type annotation (type = “org.hibernate.type.LocalDateTimeType”)

… Wait.

I have switched to Java 8 and Hibernate 5 to overcome the problem of not being able to store milliseconds in Hibernate.

p>

private LocalDateTime date = LocalDateTime.now();

public LocalDateTime getDate() {
return date;
}

Maven dependency


org.hibernate
hibernate-core
5.0.1.Final



org.hibernate
hibernate-java8
5.0.1.Final

Nevertheless, Hibernate Still storing the LocalDateTime object as a tinyblob. What am I missing? I am using MySQL 5.6.19

According to this
Hibernate Issue, the hibernate-java8 module should map it to TIMESTAMP. I tried to put a @Column(columnDefinition=“TIMESTAMP”) on the getter, But this will cause DataIntegrityViolationException.

Put @Type(type=“org.hibernate.type.LocalDateTimeType”) on the getter. The database table remains tinyblob.

As of this comment:

> Hibernate version is 5.2.10.Final
>It is not recommended to use hibernate-java8, all functions are included in hibernate- In core

Hibernate provides type converters for all JDK date/time types:

>The OffsetDateTime getter on the entity should use the @Type annotation (type = “org.hibernate.type. OffsetDateTimeType”)
>The LocalDateTime getter on the entity should use @Type annotation (type = “org.hibernate.type.LocalDateTimeType”)

…etc.

< p>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4442 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.