Hibernate version: 3.2.2
I'm using a session-scoped Interceptor to convert all timestamp attributes to UTC before persisting (in onSave, onFlushDirty methods). Works fine.
However, the in memory object after persistence needs to reflect the original timestamp values (in their original timezone). To achieve this I tried the following in postFlush:
Code:
public void postFlush(Iterator entities)
{
logger.debug("postFlush: reverting in-memory state of modified entities..");
while (entities.hasNext())
{
Object nextEntity = entities.next();
Boolean modified = modifiedState.get(nextEntity);
if (modified != null && modified.booleanValue())
{
modifiedState.put(nextEntity, Boolean.FALSE);
// revert the in memory state of this entity from pre converted values
revertConvertedState(nextEntity);
}
}
}
private void revertConvertedState(Object entity)
{
SessionImpl sessionImpl = (SessionImpl)HibernateUtils.currentSession();
EntityPersister entityPersister = sessionImpl.getEntityPersister(sessionImpl.getEntityName(entity), entity);
Object[] preConversionState = (Object[])preConversionStateMap.get(entity); // state saved before conversion during onFlushDirty
if (preConversionState != null)
{
logger.debug("reverting state for object [" + entity + "], property values [" + preConversionState + "]");
entityPersister.setPropertyValues(entity, preConversionState, EntityMode.POJO);
}
}
But setting the property values using the EntityPersister does not seem to work. And I end up with timestamp values in UTC.
Is this the right approach? Does hibernate ignore any changes to in-memory state in postFlush?