public static void processReachableCollection(PersistentCollection collection,
CollectionType type,
Object entity,
SessionImplementor session) throws HibernateException {
collection.setOwner(entity);
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);
SessionFactoryImplementor factory = session.getFactory();
CollectionPersister persister = factory.getCollectionPersister( type.getRole() );
ce.setCurrentPersister(persister);
ce.setCurrentKey( type.getKeyOfOwner(entity, session) ); //TODO: better to pass the id in as an argument?
if ( log.isDebugEnabled() ) {
log.debug(
"Collection found: " +
MessageHelper.collectionInfoString( persister, ce.getCurrentKey(), factory ) +
", was: " +
MessageHelper.collectionInfoString( ce.getLoadedPersister(), ce.getLoadedKey(), factory ) +
( collection.wasInitialized() ? " (initialized)" : " (uninitialized)" )
);
}
prepareCollectionForUpdate( collection, ce, session.getEntityMode(), factory );
}
Initialize the role of the collection. |