This post below talks about the issue a bit but I'd like to confirm whether I can have Hibernate automatically update "last update time" whenever a record is updated, or does is the responsibility of the underlying db.
All I want to do is elegantly record the update time of a record.
viewtopic.php?t=986972&highlight=Quoting from Gavin King's book : "Java Persistance with Hibernate"
Quote:
Typically, Hibernate applications need to refresh objects that contain any
properties for which the database generates values. Marking properties as gener-
ated, however, lets the application delegate this responsibility to Hibernate. Essen-
tially, whenever Hibernate issues an SQL INSERT or UPDATE for an entity that has
defined generated properties, it immediately does a SELECT afterwards to retrieve
the generated values. Use the generated switch on a property mapping to enable
this automatic refresh:
<property name="lastModified"
column="LAST_MODIFIED"
update="false"
insert="false"
generated="always"/>
.
.
With annotations, declare immutability (and automatic refresh) with the
@Generated Hibernate annotation:
@Column(updatable = false, insertable = false)
@org.hibernate.annotations.Generated(
org.hibernate.annotations.GenerationTime.ALWAYS
)
private Date lastModified;