Associates a given entity (either transient or associated with another session) to
the given session.
if ( log.isTraceEnabled() ) {
log.trace(
"reassociating transient instance: " +
MessageHelper.infoString( persister, id, event.getSession().getFactory() )
);
}
EventSource source = event.getSession();
EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
source.getPersistenceContext().checkUniqueness( key, object );
//get a snapshot
Object[] values = persister.getPropertyValues( object, source.getEntityMode() );
TypeFactory.deepCopy(
values,
persister.getPropertyTypes(),
persister.getPropertyUpdateability(),
values,
source
);
Object version = Versioning.getVersion( values, persister );
EntityEntry newEntry = source.getPersistenceContext().addEntity(
object,
Status.MANAGED,
values,
key,
version,
LockMode.NONE,
true,
persister,
false,
true //will be ignored, using the existing Entry instead
);
new OnLockVisitor( source, id, object ).process( object, persister );
persister.afterReassociate( object, source );
return newEntry;