Problems with JAVA 8 Local Date Time data type being stored as a bytea data type in PostgreSQL when using Hibernate 5.0.9

Asked 1 years ago, Updated 1 years ago, 109 views

Hibernate 5.0.9 version Dialect is using postgresql. To use the new java.time package in Java8, add jackson-datatatatype-jsr310 dependency and use it.

When the field is declared and DDL is automatically generated, postgresql will have the data type bytea.

@Column
private LocalDateTime created;

But if you look again, you can see that the value is normally inquired, but if you use the new java.time package type such as LocalDateTime, does the data type become bytea? Is it inevitable that there is a problem that cannot be recognized if you directly approach the DB client and inquire the data?

hibernate jpa postgresql bytea

2022-09-22 14:11

1 Answers

@Column(name = "run_from")
@Temporal(TemporalType.TIMESTAMP)
private LocalDateTime created;

According to https://java.net/jira/browse/JPA_SPEC-63, it should be done by default, so try it as above. I haven't checked it, but it could be a problem with postgresql jdbc driver or dialect. I remember that the dialect for postgresql is based on the postgresql version, so it would be good to check it out.

And if it doesn't work, it would be better to refer to the http://www.thoughts-on-java.org/persist-localdate-localdatetime-jpa/ link. Change LocalDateTime to java.sql.Timestamp in Database to map to the Timestamp Column in DB.


2022-09-22 14:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.