Java Code Examples for org.hibernate.UnresolvableObjectException#throwIfNull()

The following examples show how to use org.hibernate.UnresolvableObjectException#throwIfNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable)
		throws HibernateException {
	// todo : remove
	LoadEventListener.LoadType type = nullable
			? LoadEventListener.INTERNAL_LOAD_NULLABLE
			: eager
			? LoadEventListener.INTERNAL_LOAD_EAGER
			: LoadEventListener.INTERNAL_LOAD_LAZY;

	LoadEvent event = loadEvent;
	loadEvent = null;
	event = recycleEventInstance( event, id, entityName );
	fireLoad( event, type );
	Object result = event.getResult();
	if ( !nullable ) {
		UnresolvableObjectException.throwIfNull( result, id, entityName );
	}
	if ( loadEvent == null ) {
		event.setEntityClassName( null );
		event.setEntityId( null );
		event.setInstanceToLoad( null );
		event.setResult( null );
		loadEvent = event;
	}
	return result;
}
 
Example 2
Source File: SessionImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException {
	// todo : remove
	LoadEventListener.LoadType type = nullable ? 
			LoadEventListener.INTERNAL_LOAD_NULLABLE : 
			eager ? LoadEventListener.INTERNAL_LOAD_EAGER : LoadEventListener.INTERNAL_LOAD_LAZY;
	LoadEvent event = new LoadEvent(id, entityName, true, this);
	fireLoad(event, type);
	if ( !nullable ) {
		UnresolvableObjectException.throwIfNull( event.getResult(), id, entityName );
	}
	return event.getResult();
}
 
Example 3
Source File: StatelessSessionImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
	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.tracev( "Refreshing transient {0}", 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.canWriteToCache() ) {
			final EntityDataAccess cacheAccess = persister.getCacheAccessStrategy();
			if ( cacheAccess != null ) {
				final Object ck = cacheAccess.generateCacheKey(
						id,
						persister,
						getFactory(),
						getTenantIdentifier()
				);
				cacheAccess.evict( ck );
			}
		}

		String previousFetchProfile = this.getLoadQueryInfluencers().getInternalFetchProfile();
		Object result = null;
		try {
			this.getLoadQueryInfluencers().setInternalFetchProfile( "refresh" );
			result = persister.load( id, entity, getNullSafeLockMode( lockMode ), this );
		}
		finally {
			this.getLoadQueryInfluencers().setInternalFetchProfile( previousFetchProfile );
		}
		UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
	}
 
Example 4
Source File: StatelessSessionImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void refresh(String entityName, Object entity, LockMode lockMode) {
		final EntityPersister persister = this.getEntityPersister( entityName, entity );
		final Serializable id = persister.getIdentifier( entity, getEntityMode() );
		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 = new CacheKey(
					id,
			        persister.getIdentifierType(),
			        persister.getRootEntityName(),
			        this.getEntityMode(),
			        this.getFactory()
			);
			persister.getCache().remove(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() );
	}