HI,
我的POJO课程是
@Entity
@Table(name = "seed")
public class SeedUrl {
@Id
SeedUrlPrimaryKey primaryKey = new SeedUrlPrimaryKey();
@Temporal(TemporalType.TIMESTAMP)
@Column
private Date lastUpdated;
public SeedUrl(String url){
this.url = url;
}
public SeedUrl(){}
public SeedUrlPrimaryKey getPrimaryKey() {
return primaryKey;
}
public void setPrimaryKey(SeedUrlPrimaryKey primaryKey) {
this.primaryKey = primaryKey;
}
@PrePersist
@PreUpdate
public void onLastUpdated() {
this.lastUpdated = new Date();
}
}
我想在插入或更新时更新同一列..
我正在按如下方式保存对象:
SeedUrlPrimaryKey primaryKey = new SeedUrlPrimaryKey();
primaryKey.setSeedId("111121123");
seedUrl.setPrimaryKey(primaryKey);
session.save(seedUrl);
session.getTransaction().commit()
但是在数据库中,lastUpdated的值为null。 在DB中,该列被声明为TIMESTAMP 我哪里错了?