protected boolean isConnectedToSession() { return session != null && session.isOpen() && session.getPersistenceContext().containsCollection( this ); }
private void checkNotAssociatedWithOtherPersistenceContextIfMutable(ManagedEntity managedEntity) { // we only have to check mutable managedEntity final AbstractEntityEntry entityEntry = (AbstractEntityEntry) managedEntity.$$_hibernate_getEntityEntry(); if ( entityEntry == null || !entityEntry.getPersister().isMutable() || entityEntry.getPersistenceContext() == null || entityEntry.getPersistenceContext() == persistenceContext ) { return; } if ( entityEntry.getPersistenceContext().getSession().isOpen() ) { // NOTE: otherPersistenceContext may be operating on the entityEntry in a different thread. // it is not safe to associate entityEntry with this EntityEntryContext. throw new HibernateException( "Illegal attempt to associate a ManagedEntity with two open persistence contexts. " + entityEntry ); } else { // otherPersistenceContext is associated with a closed PersistenceContext log.stalePersistenceContextInEntityEntry( entityEntry.toString() ); } }
else if ( !session.isOpen() ) { if ( consumer.allowLoadOutsideTransaction() ) { session = openTemporarySessionForLoading( lazyInitializationWork );
protected boolean isConnectedToSession() { return session != null && session.isOpen() && session.getPersistenceContext().containsCollection( this ); }
private Object getProxyOrNull() { final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), session, getEntityName() ); if ( entityKey != null && session != null && session.isOpen() ) { 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.isOpen() ) { 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.isOpen() ) { final EntityKey key = session.generateEntityKey( getIdentifier(), session.getFactory().getMetamodel().entity( getEntityName() ) ); final Object entity = session.getPersistenceContext().getEntity( key ); if ( entity != null ) { setImplementation( entity ); } } }
else if ( !session.isOpen() ) { if ( consumer.allowLoadOutsideTransaction() ) { session = openTemporarySessionForLoading( lazyInitializationWork );
private void checkNotAssociatedWithOtherPersistenceContextIfMutable(ManagedEntity managedEntity) { // we only have to check mutable managedEntity final AbstractEntityEntry entityEntry = (AbstractEntityEntry) managedEntity.$$_hibernate_getEntityEntry(); if ( entityEntry == null || !entityEntry.getDescriptor().getJavaTypeDescriptor().getMutabilityPlan().isMutable() || entityEntry.getPersistenceContext() == null || entityEntry.getPersistenceContext() == persistenceContext ) { return; } if ( entityEntry.getPersistenceContext().getSession().isOpen() ) { // NOTE: otherPersistenceContext may be operating on the entityEntry in a different thread. // it is not safe to associate entityEntry with this EntityEntryContext. throw new HibernateException( "Illegal attempt to associate a ManagedEntity with two open persistence contexts. " + entityEntry ); } else { // otherPersistenceContext is associated with a closed PersistenceContext log.stalePersistenceContextInEntityEntry( entityEntry.toString() ); } }
else if ( session.isOpen() && session.isConnected() ) { target = session.immediateLoad( entityName, id ); initialized = true;