This is what happens in SessionImpl.saveOrUpdate:
Code:
Boolean isUnsaved = interceptor.isUnsaved(object);
ClassPersister persister = getPersister(object);
if (isUnsaved==null) {
// use unsaved-value
if ( persister.isUnsaved(object) ) {
log.trace("saveOrUpdate() unsaved instance");
save(obj);
}
else {
Serializable id = persister.getIdentifier(object);
if ( log.isTraceEnabled() ) log.trace("saveOrUpdate() previously saved instance with id: " + id);
doUpdate(object, id, persister);
}
}
else {
if ( isUnsaved.booleanValue() ) {
log.trace("saveOrUpdate() unsaved instance");
save(obj);
}
else {
log.trace("saveOrUpdate() previously saved instance");
doUpdate( object, persister.getIdentifier(object), persister );
}
}