Java Code Examples for org.hibernate.persister.entity.EntityPersister#instantiate()

The following examples show how to use org.hibernate.persister.entity.EntityPersister#instantiate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * give the interceptor an opportunity to override the default instantiation
 */
@Override
public Object instantiate(EntityPersister persister, Serializable id) throws HibernateException {
	checkOpenOrWaitingForAutoClose();
	checkTransactionSynchStatus();
	Object result = getInterceptor().instantiate(
			persister.getEntityName(),
			persister.getEntityMetamodel().getEntityMode(),
			id
	);
	if ( result == null ) {
		result = persister.instantiate( id, this );
	}
	delayedAfterCompletion();
	return result;
}
 
Example 2
Source File: SessionImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * give the interceptor an opportunity to override the default instantiation
 */
public Object instantiate(EntityPersister persister, Serializable id) throws HibernateException {
	errorIfClosed();
	checkTransactionSynchStatus();
	Object result = interceptor.instantiate( persister.getEntityName(), entityMode, id );
	if ( result == null ) {
		result = persister.instantiate( id, entityMode );
	}
	return result;
}
 
Example 3
Source File: DefaultMergeEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void entityIsTransient(MergeEvent event, Map copyCache) {
	
	log.trace("merging transient instance");
	
	final Object entity = event.getEntity();
	final EventSource source = event.getSession();

	final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
	final String entityName = persister.getEntityName();
	
	final Serializable id = persister.hasIdentifierProperty() ?
			persister.getIdentifier( entity, source.getEntityMode() ) :
	        null;
	
	final Object copy = persister.instantiate( id, source.getEntityMode() );  //TODO: should this be Session.instantiate(Persister, ...)?
	copyCache.put(entity, copy); //before cascade!
	
	// cascade first, so that all unsaved objects get their
	// copy created before we actually copy
	//cascadeOnMerge(event, persister, entity, copyCache, Cascades.CASCADE_BEFORE_MERGE);
	super.cascadeBeforeSave(source, persister, entity, copyCache);
	copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT);
	
	//this bit is only *really* absolutely necessary for handling 
	//requestedId, but is also good if we merge multiple object 
	//graphs, since it helps ensure uniqueness
	final Serializable requestedId = event.getRequestedId();
	if (requestedId==null) {
		saveWithGeneratedId( copy, entityName, copyCache, source, false );
	}
	else {
		saveWithRequestedId( copy, requestedId, entityName, copyCache, source );
	}
	
	// cascade first, so that all unsaved objects get their 
	// copy created before we actually copy
	super.cascadeAfterSave(source, persister, entity, copyCache);
	copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_TO_PARENT);
	
	event.setResult(copy);

}