4

I'm trying to generate creation and update timestamps and as per this jboss link I have the following code inside my Hibernate model file:

@CreationTimestamp
@Column(name = "create_date")
private Date createDate;

@UpdateTimestamp
@Column(name = "update_date")
private Date updateDate;

When I run my test, the Postgres server gives the following error "ERROR: null value in column "create_date" violates not-null constraint." after commiting.

However, everything works If I change the above code to the following:

private Date createDate;
private Date updateDate;

@CreationTimestamp
@Column(name = "create_date")
public Date getCreateDate() {
    return this.createDate;
}

public void setCreateDate(Date createDate) {
    this.createDate = createDate;
}

@UpdateTimestamp
@Column(name = "update_date")
public Date getUpdateDate() {
    return this.updateDate;
}

public void setUpdateDate(Date updateDate) {
    this.updateDate = updateDate;
}

I know that it should work using the first method as well, but I haven't been able to find why it won't work without the getters and setters.

Yogesh Prajapati
  • 4,770
  • 2
  • 36
  • 77
Alex
  • 75
  • 1
  • 6

0 Answers0