【发布时间】:2016-06-12 07:21:03
【问题描述】:
在应用程序部署期间,JPA @Temporal(TemporalType.DATE) 注释存在一些问题。 所以我创建了 spring data + postgres 9.5 + hibernate 4.3.10 应用程序并将 hbm2ddl.auto 设置为 'validate'。
hibernate.hbm2ddl.auto = validate
这里是实体:
@Entity
@Table(name = "locomotive")
public class LocomotiveEntity {
private Long locomotiveId;
@Column(name = "status")
private int status;
@Temporal(TemporalType.DATE)
private java.util.Date constructionYear;
...
我还使用此脚本创建了 locomotive 表:
CREATE TABLE "locomotive"
(
"locomotiveId" bigserial PRIMARY KEY,
"status" integer NOT NULL,
"constructionYear" DATE NOT NULL
);
但我在部署期间看到异常:
Caused by: org.hibernate.HibernateException: Wrong
column type in public.constructionYear for column constructionYear.
Found: date, expected: timestamp
所以我的数据库中有“DATE”类型列,以及“DATE”java 类型。我做错了什么?
【问题讨论】:
-
如果您查看PostgreSQL documentation,您会看到
date类型不包括一天中的时间。你必须至少使用timestamp。
标签: java spring hibernate postgresql jpa