简体   繁体   English

JSF——新时间戳覆盖旧记录

[英]JSF -- new timestamp overrides the old record

I have generated a web CRUD application inside netbenas ide.我在 netbenas ide 中生成了一个 web CRUD 应用程序。

The following are snipplets of an entity class:以下是实体类的片段:

@Column(name = "TESTTIMESTAMP")
@Temporal(TemporalType.TIMESTAMP)    
private Date testtimestamp;  

public Date getTesttimestamp() {    
   long ts = new Date().getTime() + TimeZone.getTimeZone("Australia/Sydney").getOffset(new Date().getTime());
   testtimestamp = new Date(ts);
   return testtimestamp;
}

public void setTesttimestamp(Date testtimestamp) {                        
   this.testtimestamp = testtimestamp;
}

When I create a record from web page it has correct timestamp value.当我从网页创建记录时,它具有正确的时间戳值。 But if I create another record using the same page both timestamp (old and new) set to the same new value.但是,如果我使用同一页面创建另一条记录,则时间戳(旧的和新的)都设置为相同的新值。 How to fix this?如何解决这个问题?

fixed it修复

public Test() {
        long ts = new Date().getTime() + TimeZone.getTimeZone("Australia/Sydney").getOffset(new Date().getTime());
        testtimestamp = new Date(ts);
}

public Test(Integer testid) {
        this();
        this.testid = testid;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM