【发布时间】:2017-06-02 10:42:17
【问题描述】:
我有一个实体,它扩展了一个名为 AbstractAuditingEntity 的审计实体类,其中一个字段是
@CreatedDate
@Column(name = "created_date", nullable = false)
@JsonIgnore
private ZonedDateTime createdDate
以上字段映射到名为"created_date" 的数据库字段,类型为"timestamp without time zone"。
但是在保存这个实体的时候,PostgresSQL 会抛出如下错误:
Caused by: org.postgresql.util.PSQLException: ERROR: column "created_date" is of type timestamp without time zone but expression is of type bytea
Hint: You will need to rewrite or cast the expression.
我在这里寻找相同的错误并找到了解决方案:Postgresql UUID supported by Hibernate?
但是解决方案是针对java.util.UUID,在解决方案中建议在UUID类型的字段上添加注解@Type(type="pg-uuid")。
有没有像 pg-uuid 这样的现成类型值用于 ZonedDateTime ? hibernate @Type 注释的不同值常量的任何参考链接?
或者应该写一个自定义的反序列化器类?如何编写这样的反序列化器类有参考链接?
PostgresSQL Version : 9.6,
<liquibase-hibernate5.version>3.6</liquibase-hibernate5.version>
【问题讨论】:
-
您可以在您的记录器中启用
org.hibernate.type的调试日志吗?如果类型已注册 pastebin.com/t2xh5UvM 并且应该可以工作,您应该会找到类似的内容。 -
在 Hibernate 5.2 之前,Java 8 时间类的处理来自一个可选模块。
标签: java spring postgresql hibernate