Code example for PersistenceContext

Methods: getCollectionEntrygetEntitygetEntry

0
			processDereferencedCollection(coll, session); 
		} 
	} 
 
	private static void processDereferencedCollection(PersistentCollection coll, SessionImplementor session) { 
		final PersistenceContext persistenceContext = session.getPersistenceContext(); 
		CollectionEntry entry = persistenceContext.getCollectionEntry(coll); 
		final CollectionPersister loadedPersister = entry.getLoadedPersister(); 
 
        if (LOG.isDebugEnabled() && loadedPersister != null) { 
			LOG.debugf( 
					"Collection dereferenced: %s", 
					MessageHelper.collectionInfoString( 
							loadedPersister, 
							entry.getLoadedKey(), 
							session.getFactory() 
					) 
			); 
		} 
 
		// do a check 
		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() ) { 
					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" ); 
				} 
			} 
			EntityKey key = session.generateEntityKey( ownerId, loadedPersister.getOwnerEntityPersister() ); 
			Object owner = persistenceContext.getEntity(key); 
			if ( owner == null ) { 
				throw new AssertionFailure( 
						"collection owner not associated with session: " + 
						loadedPersister.getRole() 
				); 
			} 
			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 ) { 
Experience pair programming with AI  Get Codota for Java