Hi, I was trying to implement Oracle SYSDATE in all of my hibernate entity classes who extends Auditable abstract class which has createTimestamp and updateTimestamp. Instead of using java.util.Date() for populating these timestamps, I would like to use SYSDATE.
Is there a way of doing it? I found something regarding this in some forums about @Formula(value="select sysdate from dual") which should get sysdate from the DB but for some reason it never worked for me. I always get sysdate as null.
Can somebody please help me on this? Here is my code
Code:
@MappedSuperclass
public abstract class Auditable {
@Formula(value = "(select sysdate from dual)")
private Date sysdate;
@Column(name = "CREAT_USER", length = 20)
private String creatUser;
@Column(name = "CREAT_TMSTMP", length = 7, insertable = true, updatable = false)
private Date creatTmstmp = getSysdate();
@Column(name = "UPDT_USER", length = 20)
private String updtUser;
@Version
@Column(name = "UPDT_TMSTMP", length = 7, insertable = true, updatable = true)
private Date updtTmstmp;
public String getCreatUser() {
return this.creatUser;
}
public void setCreatUser(String creatUser) {
this.creatUser = creatUser;
}
public Date getCreatTmstmp() {
return this.creatTmstmp;
}
public void setCreatTmstmp(Date creatTmstmp) {
this.creatTmstmp = creatTmstmp;
}
public String getUpdtUser() {
return this.updtUser;
}
public void setUpdtUser(String updtUser) {
this.updtUser = updtUser;
}
public Date getUpdtTmstmp() {
return this.updtTmstmp;
}
public void setUpdtTmstmp(Date updtTmstmp) {
this.updtTmstmp = updtTmstmp;
}
public Date getSysdate() {
return sysdate;
}
public void setSysdate(Date sysdate) {
this.sysdate = sysdate;
}
}