Spring数据JPA Postgresql Timestamp为null

时间:2014-10-23 10:57:04

标签: spring postgresql jpa timestamp spring-data-jpa

我正在使用PostgreSQL 9.3和spring-data-jpa 1.8.0。我创建了一个带有created_at列的表(类型 - 没有时区的时间戳):

CREATE TABLE users
(
  id bigint NOT NULL,
  created_at timestamp without time zone NOT NULL DEFAULT now(),
  updated_at timestamp without time zone NOT NULL DEFAULT now(),
  CONSTRAINT users_pkey PRIMARY KEY (id)
)

因此,如果我尝试使用此表中的实体类获取数据,则createdAt字段始终为null。我的代码:

@Column(name = "created_at", nullable = false)
@Type(type = "date")
@Temporal(value = TemporalType.TIMESTAMP)
@CreationTimestamp
public Date getCreatedAt() {
    return createdAt;
}

@PrePersist
public void onPrePersist() {
    this.setCreatedAt(new Date());
}

我做错了什么?

0 个答案:

没有答案