I have one JPA entity that has a created date and a modified date column. On creation/persist, both the created date and modified date are generated by the default value given in the database, which is a timestamp. The creation works, however, when I try to do an update/merge, I cannot figure out how to change the modified date by using the default value in the database. Any advice? This is the current setup:
....
@Temporal(TemporalType.DATE)
@Column(name="CREATED_DATE", insertable = false, updatable = false)
private Date createdDate;
@Temporal(TemporalType.DATE)
@Column(name="MODIFIED_DATE", insertable = false)
private Date modifiedDate;
....
-
public Database changeDate(Database oldValues)
Database newvalues = new Database();
....
newValues.setCreatedDate(oldValues.getCreatedDate);
//newValues.setModifiedDate(); <-- (Should use the default value in the database)
....
em.merge(newValues); <-- (EntityManager)
em.getTransaction().commit();
** Just in case I didn't make myself clear, I just don't know how to make it update with the default value set in the database.