final Date transTime = new Date(); // new Date(event.getSource().getTimestamp());
final EntityMode entityMode = event.getPersister().guessEntityMode(event.getEntity());
Object newPropValue = null;
// need to have a separate session for audit save
final StatelessSession session = event.getPersister().getFactory().openStatelessSession();
session.beginTransaction();
final String actorId = getActorId(session, event);
for (final String propertyName : event.getPersister().getPropertyNames()) {
if (!auditColumn.contains(propertyName)) {
newPropValue = event.getPersister().getPropertyValue(event.getEntity(), propertyName, entityMode);
// because we are performing an insert we only need to be concerned will non-null values
if (newPropValue != null && !(newPropValue instanceof Collection)) {
final AuditTrail auditTrail = new AuditTrail(entityId, entityName, OP_TYPE_INSERT, actorId,
transTime).entityProperty(propertyName).entityPropNewValue(
newPropValue == null ? null : newPropValue.toString());
session.insert(auditTrail);
}
}
}
session.getTransaction().commit();
} catch (final HibernateException e) {
LOGGER.error("Unable to process audit log for INSERT operation", e);
}
return false;
}