Java PersistenceContext.getEntry方法代码示例

本文整理汇总了Java中org.hibernate.engine.spi.PersistenceContext.getEntry方法的典型用法代码示例。如果您正苦于以下问题:Java PersistenceContext.getEntry方法的具体用法?Java PersistenceContext.getEntry怎么用?Java PersistenceContext.getEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.engine.spi.PersistenceContext的用法示例。


Java PersistenceContext.getEntry方法代码示例

在下文中一共展示了PersistenceContext.getEntry方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: postLoad

import org.hibernate.engine.spi.PersistenceContext; //导入方法依赖的package包/类
/**
 * PostLoad cannot occur during initializeEntity, as that call occurs *before*
 * the Set collections are added to the persistence context by Loader.
 * Without the split, LazyInitializationExceptions can occur in the Entity's
 * postLoad if it acts upon the collection.
 *
 * HHH-6043
 * 
 * @param entity The entity
 * @param session The Session
 * @param postLoadEvent The (re-used) post-load event
 */
public static void postLoad(
		final Object entity,
		final SessionImplementor session,
		final PostLoadEvent postLoadEvent) {
	
	if ( session.isEventSource() ) {
		final PersistenceContext persistenceContext
				= session.getPersistenceContext();
		final EntityEntry entityEntry = persistenceContext.getEntry( entity );

		postLoadEvent.setEntity( entity ).setId( entityEntry.getId() ).setPersister( entityEntry.getPersister() );

		final EventListenerGroup<PostLoadEventListener> listenerGroup = session.getFactory()
						.getServiceRegistry()
						.getService( EventListenerRegistry.class )
						.getEventListenerGroup( EventType.POST_LOAD );
		for ( PostLoadEventListener listener : listenerGroup.listeners() ) {
			listener.onPostLoad( postLoadEvent );
		}
	}
} 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:TwoPhaseLoad.java

示例2: createProxyIfNecessary

import org.hibernate.engine.spi.PersistenceContext; //导入方法依赖的package包/类
/**
 * If there is already a corresponding proxy associated with the
 * persistence context, return it; otherwise create a proxy, associate it
 * with the persistence context, and return the just-created proxy.
 *
 * @param event The initiating load request event
 * @param persister The persister corresponding to the entity to be loaded
 * @param keyToLoad The key of the entity to be loaded
 * @param options The defined load options
 * @param persistenceContext The originating session
 *
 * @return The created/existing proxy
 */
private Object createProxyIfNecessary(
		final LoadEvent event,
		final EntityPersister persister,
		final EntityKey keyToLoad,
		final LoadEventListener.LoadType options,
		final PersistenceContext persistenceContext) {
	Object existing = persistenceContext.getEntity( keyToLoad );
	if ( existing != null ) {
		// return existing object or initialized proxy (unless deleted)
		LOG.trace( "Entity found in session cache" );
		if ( options.isCheckDeleted() ) {
			EntityEntry entry = persistenceContext.getEntry( existing );
			Status status = entry.getStatus();
			if ( status == Status.DELETED || status == Status.GONE ) {
				return null;
			}
		}
		return existing;
	}
	LOG.trace( "Creating new proxy for entity" );
	// return new uninitialized proxy
	Object proxy = persister.createProxy( event.getEntityId(), event.getSession() );
	persistenceContext.getBatchFetchQueue().addBatchLoadableEntityKey( keyToLoad );
	persistenceContext.addProxy( keyToLoad, proxy );
	return proxy;
} 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:DefaultLoadEventListener.java

示例3: getIdentifier

import org.hibernate.engine.spi.PersistenceContext; //导入方法依赖的package包/类
@Override
public Object getIdentifier(Object entity, EntityMode entityMode, SessionImplementor session) {
	final Object id = mappedIdentifierType.instantiate( entityMode );
	final Object[] propertyValues = virtualIdComponent.getPropertyValues( entity, entityMode );
	final Type[] subTypes = virtualIdComponent.getSubtypes();
	final Type[] copierSubTypes = mappedIdentifierType.getSubtypes();
	final Iterable<PersistEventListener> persistEventListeners = persistEventListeners( session );
	final PersistenceContext persistenceContext = session.getPersistenceContext();
	final int length = subTypes.length;
	for ( int i = 0 ; i < length; i++ ) {
		if ( propertyValues[i] == null ) {
			throw new HibernateException( "No part of a composite identifier may be null" );
		}
		//JPA 2 @MapsId + @IdClass points to the pk of the entity
		if ( subTypes[i].isAssociationType() && ! copierSubTypes[i].isAssociationType() ) {
			// we need a session to handle this use case
			if ( session == null ) {
				throw new AssertionError(
						"Deprecated version of getIdentifier (no session) was used but session was required"
				);
			}
			final Object subId;
			if ( HibernateProxy.class.isInstance( propertyValues[i] ) ) {
				subId = ( (HibernateProxy) propertyValues[i] ).getHibernateLazyInitializer().getIdentifier();
			}
			else {
				EntityEntry pcEntry = session.getPersistenceContext().getEntry( propertyValues[i] );
				if ( pcEntry != null ) {
					subId = pcEntry.getId();
				}
				else {
					LOG.debug( "Performing implicit derived identity cascade" );
					final PersistEvent event = new PersistEvent( null, propertyValues[i], (EventSource) session );
					for ( PersistEventListener listener : persistEventListeners ) {
						listener.onPersist( event );
					}
					pcEntry = persistenceContext.getEntry( propertyValues[i] );
					if ( pcEntry == null || pcEntry.getId() == null ) {
						throw new HibernateException( "Unable to process implicit derived identity cascade" );
					}
					else {
						subId = pcEntry.getId();
					}
				}
			}
			propertyValues[i] = subId;
		}
	}
	mappedIdentifierType.setPropertyValues( id, propertyValues, entityMode );
	return id;
} 
开发者ID:lamsfoundation,项目名称:lams,代码行数:52,代码来源:AbstractEntityTuplizer.java

示例4: processDereferencedCollection

import org.hibernate.engine.spi.PersistenceContext; //导入方法依赖的package包/类
private static void processDereferencedCollection(PersistentCollection coll, SessionImplementor session) {
	final PersistenceContext persistenceContext = session.getPersistenceContext();
	final CollectionEntry entry = persistenceContext.getCollectionEntry( coll );
	final CollectionPersister loadedPersister = entry.getLoadedPersister();

	if ( loadedPersister != null && LOG.isDebugEnabled() ) {
		LOG.debugf(
				"Collection dereferenced: %s",
				MessageHelper.collectionInfoString( loadedPersister, 
						coll, entry.getLoadedKey(), session
				)
		);
	}

	// do a check
	final boolean hasOrphanDelete = loadedPersister != null && loadedPersister.hasOrphanDelete();
	if ( hasOrphanDelete ) {
		Serializable ownerId = loadedPersister.getOwnerEntityPersister().getIdentifier( coll.getOwner(), session );
		if ( ownerId == null ) {
			// the owning entity may have been deleted and its identifier unset due to
			// identifier-rollback; in which case, try to look up its identifier from
			// the persistence context
			if ( session.getFactory().getSettings().isIdentifierRollbackEnabled() ) {
				final EntityEntry ownerEntry = persistenceContext.getEntry( coll.getOwner() );
				if ( ownerEntry != null ) {
					ownerId = ownerEntry.getId();
				}
			}
			if ( ownerId == null ) {
				throw new AssertionFailure( "Unable to determine collection owner identifier for orphan-delete processing" );
			}
		}
		final EntityKey key = session.generateEntityKey( ownerId, loadedPersister.getOwnerEntityPersister() );
		final Object owner = persistenceContext.getEntity( key );
		if ( owner == null ) {
			throw new AssertionFailure(
					"collection owner not associated with session: " +
					loadedPersister.getRole()
			);
		}
		final EntityEntry e = persistenceContext.getEntry( owner );
		//only collections belonging to deleted entities are allowed to be dereferenced in the case of orphan delete
		if ( e != null && e.getStatus() != Status.DELETED && e.getStatus() != Status.GONE ) {
			throw new HibernateException(
					"A collection with cascade=\"all-delete-orphan\" was no longer referenced by the owning entity instance: " +
					loadedPersister.getRole()
			);
		}
	}

	// do the work
	entry.setCurrentPersister( null );
	entry.setCurrentKey( null );
	prepareCollectionForUpdate( coll, entry, session.getFactory() );

} 
开发者ID:lamsfoundation,项目名称:lams,代码行数:57,代码来源:Collections.java

示例5: initializeEntity

import org.hibernate.engine.spi.PersistenceContext; //导入方法依赖的package包/类
/**
 * Perform the second step of 2-phase load. Fully initialize the entity
 * instance.
 * <p/>
 * After processing a JDBC result set, we "resolve" all the associations
 * between the entities which were instantiated and had their state
 * "hydrated" into an array
 *
 * @param entity The entity being loaded
 * @param readOnly Is the entity being loaded as read-only
 * @param session The Session
 * @param preLoadEvent The (re-used) pre-load event
 */
public static void initializeEntity(
		final Object entity,
		final boolean readOnly,
		final SessionImplementor session,
		final PreLoadEvent preLoadEvent) {
	final PersistenceContext persistenceContext = session.getPersistenceContext();
	final EntityEntry entityEntry = persistenceContext.getEntry( entity );
	if ( entityEntry == null ) {
		throw new AssertionFailure( "possible non-threadsafe access to the session" );
	}
	doInitializeEntity( entity, entityEntry, readOnly, session, preLoadEvent );
} 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:TwoPhaseLoad.java

本文标签属性:

示例:示例英文

代码:代码编程

java:javascript18岁

PersistenceContext:PersistenceContext

getEntry:getEntry

上一篇:奔驰事件最后怎么处理(西安警方通报奔驰撞公交致5伤事件,肇事司机需要承担什么法律责任呢...)
下一篇:请问这个人是谁?(青春有你2女生版名单)(《青春有你2》虞书欣孔雪儿等你怎么这么好看青春有你二哪一期)

为您推荐