postgresql jpa hibernate异常:找到:date,expected:timestamp

时间:2016-02-29 09:50:38

标签: java spring hibernate postgresql jpa

在申请失业期间,我有一些JPA @Temporal(TemporalType.DATE)注释的问题。 所以我创建了spring数据+ postgres 9.5 + hibernate 4.3.10 app并将 hbm2ddl.auto 设置为'验证'。

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

所以我的db中有'DATE'类型列,'DATE'是java类型。我做错了什么?

1 个答案:

答案 0 :(得分:0)

尝试使用TemporalType.TIMESTAMP,如下所示:

 @Temporal(TemporalType.TIMESTAMP)
 private Date constructionYear;