if (LOG.isTraceEnabled()) LOG.trace("Starting attempt to find loading collection ["
+ MessageHelper.collectionInfoString(persister.getRole(), key) + "]");
final LoadingCollectionEntry loadingCollectionEntry = loadContexts.locateLoadingCollectionEntry( collectionKey );
if ( loadingCollectionEntry == null ) {
// look for existing collection as part of the persistence context
PersistentCollection collection = loadContexts.getPersistenceContext().getCollection( collectionKey );
if ( collection != null ) {
if ( collection.wasInitialized() ) {
LOG.trace("Collection already initialized; ignoring");
return null; // ignore this row of results! Note the early exit
}
LOG.trace("Collection not yet initialized; initializing");
}
else {
Object owner = loadContexts.getPersistenceContext().getCollectionOwner( key, persister );
final boolean newlySavedEntity = owner != null
&& loadContexts.getPersistenceContext().getEntry( owner ).getStatus() != Status.LOADING
&& em != EntityMode.DOM4J;
if ( newlySavedEntity ) {
// important, to account for newly saved entities in query
// todo : some kind of check for new status...
LOG.trace("Owning entity already loaded; ignoring");
return null;
}
// create one
LOG.trace("Instantiating new collection [key=" + key + ", rs=" + resultSet + "]");
collection = persister.getCollectionType().instantiate(loadContexts.getPersistenceContext().getSession(),
persister,
key);
}
collection.beforeInitialize( persister, -1 );
collection.beginRead();
localLoadingCollectionKeys.add( collectionKey );
loadContexts.registerLoadingCollectionXRef( collectionKey, new LoadingCollectionEntry( resultSet, persister, key, collection ) );
return collection;
}
if (loadingCollectionEntry.getResultSet() == resultSet) {