This is my blog class
@Entity
@Component
@Table
public class Blog implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
private String id;
private String name;
private String Description;
@CreationTimestamp
private Date createdOn;
@UpdateTimestamp
private Date updatedOn;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
public Date getCreatedOn() {
return createdOn;
}
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
public Date getUpdatedOn() {
return updatedOn;
}
public void setUpdatedOn(Date updatedOn) {
this.updatedOn = updatedOn;
}
}
timestamps createdOn and updatedOn are stored successfully when new blog is created but when existing blog is updated updatedOn field is updated whereas createdOn field becomes null. I want createdOn field to retain the timestamp on which it is created. Can someone help out ?
Add updateable=false annotation to the field , whom you don't want to update.
Below are the sample code for createddate (only insertable) and modifieddate (insertable/updateable)
@Column(name = "CreatedDate", updatable=false)
@CreationTimestamp
private Timestamp createdDate;
@Column(name = "ModifiedDate")
@UpdateTimestamp
private Timestamp modifiedDate;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With