In the Hibernate Core reference documentation there is a sample implementation of an AuditInterceptor class.
In its onFlushDirty() and onSave() methods a for loop over all the properties of the entity class is used to find the properties "lastUpdateTimestamp" and "createUser". The code looks like this
Code:
for ( int i=0; i < propertyNames.length; i++ ) {
if ( "lastUpdateTimestamp".equals( propertyNames[i] ) ) {
currentState[i] = new Date();
return true;
}
}
Is this sample code something one would use in practice? Iterating over all the propertyNames each time an object is saved or updated seems kind of slow.
Is the order of the properties in the arrays something that can change while a system is running? Or can I rely on the order of the properties in the arrays being the same as the order in the mapping files or at least being fixed during runtime.
I would like to either use fixed indexes (something like the last property index etc.) or run through this loop once and store the correct indexes for each entity class in a HashMap.
I'd appreciate your input on this.[/code]