private void errorIfReadOnlySettingNotAvailable() { if ( session == null ) { throw new TransientObjectException( "Proxy [" + entityName + "#" + id + "] is detached (i.e, session is null). The read-only/modifiable setting is only accessible when the proxy is associated with an open session." ); } if ( !session.isOpenOrWaitingForAutoClose() ) { throw new SessionException( "Session is closed. The read-only/modifiable setting is only accessible when the proxy [" + entityName + "#" + id + "] is associated with an open session." ); } }
private Object getProxyOrNull() { final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), session, getEntityName() ); if ( entityKey != null && session != null && session.isOpenOrWaitingForAutoClose() ) { return session.getPersistenceContext().getProxy( entityKey ); } return null; }
@Override public final void initialize() throws HibernateException { if ( !initialized ) { if ( allowLoadOutsideTransaction ) { permissiveInitialization(); } else if ( session == null ) { throw new LazyInitializationException( "could not initialize proxy [" + entityName + "#" + id + "] - no Session" ); } else if ( !session.isOpenOrWaitingForAutoClose() ) { throw new LazyInitializationException( "could not initialize proxy [" + entityName + "#" + id + "] - the owning Session was closed" ); } else if ( !session.isConnected() ) { throw new LazyInitializationException( "could not initialize proxy [" + entityName + "#" + id + "] - the owning Session is disconnected" ); } else { target = session.immediateLoad( entityName, id ); initialized = true; checkTargetState(session); } } else { checkTargetState(session); } }
/** * Attempt to initialize the proxy without loading anything from the database. * * This will only have any effect if the proxy is still attached to a session, * and the entity being proxied has been loaded and added to the persistence context * of that session since the proxy was created. */ public final void initializeWithoutLoadIfPossible() { if ( !initialized && session != null && session.isOpenOrWaitingForAutoClose() ) { final EntityKey key = session.generateEntityKey( getIdentifier(), session.getFactory().getMetamodel().entityPersister( getEntityName() ) ); final Object entity = session.getPersistenceContext().getEntity( key ); if ( entity != null ) { setImplementation( entity ); } } }
else if ( !session.isOpenOrWaitingForAutoClose() ) { if ( allowLoadOutsideTransaction ) { tempSession = openTemporarySessionForLoading();
else if ( session.isOpenOrWaitingForAutoClose() && session.isConnected() ) { target = session.immediateLoad( entityName, id ); initialized = true;
else if ( !session.isOpenOrWaitingForAutoClose() ) { if ( allowLoadOutsideTransaction ) { tempSession = openTemporarySessionForLoading();