我有一个抽象类,我的所有持久化对象都从它扩展而来,请参阅下面。creationDate和modifiedDate字段是在对象最初保存时填充的,我可以在表中看到日期。我遇到的问题是,当我更新同一个对象时,creationDate和modifiedDate也会更新,我只想更新modifiedDate字段。
我正在和ebean一起使用play 2.1。
抽象类。。。
@MappedSuperclass
public abstract class BasePersistableEntity extends Model {
@Temporal(TemporalType.TIMESTAMP)
@Formats.DateTime(pattern="yyyy-MM-dd HH:mm:ss")
@CreatedTimestamp
protected Date creationDate;
@Temporal(TemporalType.TIMESTAMP)
@Formats.DateTime(pattern="yyyy-MM-dd HH:mm:ss")
@UpdatedTimestamp
@Version
protected Date modifiedDate;
public Date getCreationDate(){
return creationDate;
}
public void setCreationDate(Date date){
creationDate = date;
}
public Date getModifiedDate(){
return modifiedDate;
}
public void setModifiedDate(Date date){
modifiedDate = date;
}
}
谢谢。
@Temporal(TemporalType.TIMESTAMP)
@Formats.DateTime(pattern="yyyy-MM-dd HH:mm:ss")
@CreatedTimestamp
@Column(updatable=false)
protected Date creationDate;
只需将@Column(updateable=false)注释添加到creationDate字段