本文整理汇总了Java中org.hibernate.collection.spi.PersistentCollection.setOwner方法的典型用法代码示例。如果您正苦于以下问题:Java PersistentCollection.setOwner方法的具体用法?Java PersistentCollection.setOwner怎么用?Java PersistentCollection.setOwner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.collection.spi.PersistentCollection
的用法示例。
在下文中一共展示了PersistentCollection.setOwner方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processReachableCollection
import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
* Initialize the role of the collection.
*
* @param collection The collection to be updated by reachability.
* @param type The type of the collection.
* @param entity The owner of the collection.
* @param session The session from which this request originates
*/
public static void processReachableCollection(
PersistentCollection collection,
CollectionType type,
Object entity,
SessionImplementor session) {
collection.setOwner( entity );
final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( collection );
if ( ce == null ) {
// refer to comment in StatefulPersistenceContext.addCollection()
throw new HibernateException(
"Found two representations of same collection: " +
type.getRole()
);
}
// The CollectionEntry.isReached() stuff is just to detect any silly users
// who set up circular or shared references between/to collections.
if ( ce.isReached() ) {
// We've been here before
throw new HibernateException(
"Found shared references to a collection: " + type.getRole()
);
}
ce.setReached( true );
final SessionFactoryImplementor factory = session.getFactory();
final CollectionPersister persister = factory.getCollectionPersister( type.getRole() );
ce.setCurrentPersister( persister );
//TODO: better to pass the id in as an argument?
ce.setCurrentKey( type.getKeyOfOwner( entity, session ) );
if ( LOG.isDebugEnabled() ) {
if ( collection.wasInitialized() ) {
LOG.debugf(
"Collection found: %s, was: %s (initialized)",
MessageHelper.collectionInfoString( persister, collection, ce.getCurrentKey(), session ),
MessageHelper.collectionInfoString( ce.getLoadedPersister(), collection, ce.getLoadedKey(), session )
);
}
else {
LOG.debugf(
"Collection found: %s, was: %s (uninitialized)",
MessageHelper.collectionInfoString( persister, collection, ce.getCurrentKey(), session ),
MessageHelper.collectionInfoString( ce.getLoadedPersister(), collection, ce.getLoadedKey(), session )
);
}
}
prepareCollectionForUpdate( collection, ce, factory );
}
示例2: getCollection
import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
* instantiate a collection wrapper (called when loading an object)
*
* @param key The collection owner key
* @param session The session from which the request is originating.
* @param owner The collection owner
* @return The collection
*/
public Object getCollection(Serializable key, SessionImplementor session, Object owner) {
CollectionPersister persister = getPersister( session );
final PersistenceContext persistenceContext = session.getPersistenceContext();
final EntityMode entityMode = persister.getOwnerEntityPersister().getEntityMode();
// check if collection is currently being loaded
PersistentCollection collection = persistenceContext.getLoadContexts().locateLoadingCollection( persister, key );
if ( collection == null ) {
// check if it is already completely loaded, but unowned
collection = persistenceContext.useUnownedCollection( new CollectionKey(persister, key, entityMode) );
if ( collection == null ) {
// create a new collection wrapper, to be initialized later
collection = instantiate( session, persister, key );
collection.setOwner(owner);
persistenceContext.addUninitializedCollection( persister, collection, key );
// some collections are not lazy:
if ( initializeImmediately() ) {
session.initializeCollection( collection, false );
}
else if ( !persister.isLazy() ) {
persistenceContext.addNonLazyCollection( collection );
}
if ( hasHolder() ) {
session.getPersistenceContext().addCollectionHolder( collection );
}
}
if ( LOG.isTraceEnabled() ) {
LOG.tracef( "Created collection wrapper: %s",
MessageHelper.collectionInfoString( persister, collection,
key, session ) );
}
}
collection.setOwner(owner);
return collection.getValue();
}