HI,
My POJO class is
@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();
}
}
I want to update the same column either on insert or update ..
I am saving the object as follows:
SeedUrlPrimaryKey primaryKey = new SeedUrlPrimaryKey();
primaryKey.setSeedId("111121123");
开发者_如何转开发 seedUrl.setPrimaryKey(primaryKey);
session.save(seedUrl);
session.getTransaction().commit()
But in the Database the value of lastUpdated is coming as null.. In DB the column is declared as TIMESTAMP.
Where am i going wrong ?When you use Hibernate via Session
interface, JPA callback methods (@PrePersist
, etc) don't work. You can use Hibernate listeners instead.
精彩评论