我正在玩JPA(Eclipselink是具体的).下面的实体有一个时间戳,应该反映上次更新该实体的时间.
每次更改此实体时,JPA更新时间戳的策略是什么?
如果我还想要一个'创建'时间戳,我只会在实体首次持久化时设置,从不允许再次更改?
@Entity
public class Item implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String note;
public Item () {
}
@Id
@GeneratedValue(strategy=SEQUENCE)
@Column(unique=true, nullable=false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(length=255)
@Column(nullable=false)
public String getNote() {
return this.note;
}
public void setNote(String note) {
this.note = note;
}
@Column(nullable=false)
public Timestamp getUpdated() {
return this.updated;
}
public void setUpdated(Timestamp updated) {
this.updated = updated;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23436 次 |
| 最近记录: |