I thought it may be possible to add a lastModifiedDate to my persistent objects using a custom UserType. I want to keep this as unobtrusive as possible so I chose UserType over an Hibernate session interceptor.
However, it is not working as I intended. I extended DateType and overrode the following method:
Code:
public void set(PreparedStatement st, Object value, int index) throws SQLException {
super.set(st, new java.util.Date(), index);
}
a snippet of my mapping file is here:
Code:
<property
name="lastUpdated"
type="us.oh.state.dot.common.domain.type.UpdateTimestamp"
column="LAST_UPDATED_DT"
not-null="true"
/>
This would probably work, but Hibernate does not call set unless it detects the field is dirty. I thought I could override the isDirty check in the UserType but it seems isDirty is not called during the Session.save() call (Insert).
Anyone have any ideas?