I'm checking Pascal's answer as the correct answer as he pointed me directly to the point in the documentation that provided detail and example code. But for the reader, I'm adding more detail here.
I tried both the hibernate events as well as the interceptors, and found that an interceptor worked better in my situation. It was relatively easy to implement.
Thanks for the help!
Below is the code for the interceptor:
public class AuditInterceptor extends EmptyInterceptor {
private Log log = LogFactory.getLog(this.getClass());
private int updates;
private int creates;
@Override
public boolean onSave(Object entity, Serializable id, Object[] state,
String[] propertyNames, Type[] types) {
if (entity instanceof AuditableVO) {
creates++;
// Find the create date and change it
for (int i=0; i < propertyNames.length; i++) {
if (propertyNames[i].equals("createDate")) {
state[i] = new Date();
return true;
}
}
}
return false;
}
@Override
public boolean onFlushDirty(Object entity, Serializable id,
Object[] currentState, Object[] previousState,
String[] propertyNames, Type[] types) {
if (entity instanceof AuditableVO) {
updates++;
// Find the update date and change it
for (int i=0; i < propertyNames.length; i++) {
if (propertyNames[i].equals("updateDate")) {
currentState[i] = new Date();
return true;
}
}
}
return false;
}
@Override
public void afterTransactionCompletion(Transaction tx) {
if (tx.wasCommitted()) {
log.info("Creations: " + creates + ", Updates: " + updates);
}
creates = 0;
updates = 0;
super.afterTransactionCompletion(tx);
}
}