Code example for PersistenceContext

Methods: cleargetEntityisLoadFinished

0
 
	public void refresh(String entityName, Object entity, LockMode lockMode) { 
		final EntityPersister persister = this.getEntityPersister( entityName, entity ); 
		final Serializable id = persister.getIdentifier( entity, this ); 
        if (LOG.isTraceEnabled()) LOG.trace("Refreshing transient " + MessageHelper.infoString(persister, id, this.getFactory())); 
		// TODO : can this ever happen??? 
//		EntityKey key = new EntityKey( id, persister, source.getEntityMode() ); 
//		if ( source.getPersistenceContext().getEntry( key ) != null ) { 
//			throw new PersistentObjectException( 
//					"attempted to refresh transient instance when persistent " + 
//					"instance was already associated with the Session: " + 
//					MessageHelper.infoString( persister, id, source.getFactory() ) 
//			); 
//		} 
 
		if ( persister.hasCache() ) { 
			final CacheKey ck = generateCacheKey( id, persister.getIdentifierType(), persister.getRootEntityName() ); 
			persister.getCacheAccessStrategy().evict( ck ); 
		} 
 
		String previousFetchProfile = this.getFetchProfile(); 
		Object result = null; 
		try { 
			this.setFetchProfile( "refresh" ); 
			result = persister.load( id, entity, lockMode, this ); 
		} 
		finally { 
			this.setFetchProfile( previousFetchProfile ); 
		} 
		UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() ); 
	} 
 
	public Object immediateLoad(String entityName, Serializable id) 
			throws HibernateException { 
		throw new SessionException("proxies cannot be fetched by a stateless session"); 
	} 
 
	public void initializeCollection( 
			PersistentCollection collection, 
	        boolean writing) throws HibernateException { 
		throw new SessionException("collections cannot be fetched by a stateless session"); 
	} 
 
	public Object instantiate( 
			String entityName, 
	        Serializable id) throws HibernateException { 
		errorIfClosed(); 
		return getFactory().getEntityPersister( entityName ) 
				.instantiate( id, this ); 
	} 
 
	public Object internalLoad( 
			String entityName, 
	        Serializable id, 
	        boolean eager, 
	        boolean nullable) throws HibernateException { 
		errorIfClosed(); 
		EntityPersister persister = getFactory().getEntityPersister( entityName ); 
		// first, try to load it from the temp PC associated to this SS 
		Object loaded = temporaryPersistenceContext.getEntity( generateEntityKey( id, persister ) ); 
		if ( loaded != null ) { 
			// we found it in the temp PC.  Should indicate we are in the midst of processing a result set 
			// containing eager fetches via join fetch 
			return loaded; 
		} 
		if ( !eager && persister.hasProxy() ) { 
			// if the metadata allowed proxy creation and caller did not request forceful eager loading, 
			// generate a proxy 
			return persister.createProxy( id, this ); 
		} 
		// otherwise immediately materialize it 
		return get( entityName, id ); 
	} 
 
	public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException { 
		throw new UnsupportedOperationException(); 
	} 
 
	public Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters) 
	throws HibernateException { 
		throw new UnsupportedOperationException(); 
	} 
 
	public List listFilter(Object collection, String filter, QueryParameters queryParameters) 
	throws HibernateException { 
		throw new UnsupportedOperationException(); 
	} 
 
 
	public boolean isOpen() { 
		return !isClosed(); 
	} 
 
	public void close() { 
		managedClose(); 
	}