FileDocCategorySizeDatePackage
AbstractReassociateEventListener.javaAPI DocHibernate 3.2.52597Thu Dec 07 14:53:42 GMT 2006org.hibernate.event.def

AbstractReassociateEventListener

public class AbstractReassociateEventListener extends Object implements Serializable
A convenience base class for listeners that respond to requests to reassociate an entity to a session ( such as through lock() or update() ).
author
Gavin King

Fields Summary
private static final Log
log
Constructors Summary
Methods Summary
protected final org.hibernate.engine.EntityEntryreassociate(org.hibernate.event.AbstractEvent event, java.lang.Object object, java.io.Serializable id, org.hibernate.persister.entity.EntityPersister persister)
Associates a given entity (either transient or associated with another session) to the given session.

param
event The event triggering the re-association
param
object The entity to be associated
param
id The id of the entity.
param
persister The entity's persister instance.
return
An EntityEntry representing the entity within this 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;