简体   繁体   中英

Hibernate 5.2.10 DDL auto-update to AWS RDS (MySql 5.6.10a) creates TINYBLOB for Instant

I have a JPA @Entity with an @Column of type java.time.Instant. My understanding is this should map to a column type of TIMESTAMP. However, Hibernate auto-update created the column with type TINYBLOB, and the data it stores there is not translatable back to an Instant. I manually updated the @Column type to TIMESTAMP, but Hibernate still fails because it tries to insert data in the TINYBLOB format. I read here that Hibernate 5 handled JDK 8 classes out of the box, so I am wondering why that seems not to be the case. I worked around the problem using java.sql.Timestamp, but I have to ask, is there a way to make Hibernate persist Instant as a Timestamp? Is this an issue with the JDBC driver or the older version of MySQL provided by AWS RDS?

Adding hibernate-java8 dependency should solve your problem. By default, Java's Instant becomes datetime in RDS.

Example for maven pom.xml:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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