I have a Kotlin app built on Spring Boot 2.3.4. This version of Spring Boot includes Hibernate 5.4.21. I've also imported mysql-connector-java 8.0.21.
Whenever I try to persist an Instant object into my database, I get the following exception:
com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect datetime value: '\xAC\xED\x00\x05sr\x00\x0Djava.time.Ser\x95]\x84\xBA\x1B"H\xB2\x0C\x00\x00xpw\x0D\x02\x00\x00\x00\x00_\xCDvA)\xE6Jxx' for column 'myDateTimeColumn' at row 1
Here's the object I'm trying to persist, in Kotlin; it only has two fields:
@Entity
class RoomEntity{
@Id
lateinit var roomId: String
lateinit var lastAccessedAt: Instant
}
The table I'm trying to save it to has two columns: roomId
is a CHAR(7), and lastAccessedAt
is a TIMESTAMP.
The code that does the save is only 2 lines long:
val sql = "INSERT INTO mydb.rooms (roomId, lastAccessedAt) VALUES (?, ?);"
db.update(sql, "1234567", Instant.now())
I've looked at other SO posts similar to my issue, but the answers all say to update to version 5.2+ of Hibernate, which I am using. What could be causing this exception?