if ( refreshedAlready.containsKey(object) ) {
log.trace("already refreshed");
return;
}
final EntityEntry e = source.getPersistenceContext().getEntry( object );
final EntityPersister persister;
final Serializable id;
if ( e == null ) {
persister = source.getEntityPersister(null, object); //refresh() does not pass an entityName
id = persister.getIdentifier( object, event.getSession().getEntityMode() );
if ( log.isTraceEnabled() ) {
log.trace(
"refreshing transient " +
MessageHelper.infoString( persister, id, source.getFactory() )
);
}
EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
if ( source.getPersistenceContext().getEntry(key) != null ) {
throw new PersistentObjectException(
"attempted to refresh transient instance when persistent instance was already associated with the Session: " +
MessageHelper.infoString(persister, id, source.getFactory() )
);
}
}
else {
if ( log.isTraceEnabled() ) {
log.trace(
"refreshing " +
MessageHelper.infoString( e.getPersister(), e.getId(), source.getFactory() )
);
}
if ( !e.isExistsInDatabase() ) {
throw new HibernateException( "this instance does not yet exist as a row in the database" );
}
persister = e.getPersister();
id = e.getId();
}
// cascade the refresh prior to refreshing this entity
refreshedAlready.put(object, object);
new Cascade(CascadingAction.REFRESH, Cascade.BEFORE_REFRESH, source)