How to map timestamp column to JPA type?

I didn't solve the problem exactly, but I worked around it.

Instead of having the database supply the default value of now(), I expressed it in JPA with @PrePersist:

@Column(name="created_at", nullable=false)
@Temporal(TemporalType.TIMESTAMP)
public Date createdAt;

@PrePersist
protected void onCreate() {
    createdAt = new Date();
}

That works fine! Inspiration taken from this answer. I'm still not sure why Hibernate didn't get updated with the default value that was applied in the database. It was stuck thinking the value was still null.


Try this:

@Column(name="create_at", insertable=false)
@Temporal(TemporalType.TIMESTAMP)
private Date createAt;