/** * Is the collection currently connected to an open session? */ private final boolean isConnectedToSession() { return session!=null && session.isOpen(); }
public final void setSession(SessionImplementor s) throws HibernateException { if (s!=session) { if ( session!=null && session.isOpen() ) { //TODO: perhaps this should be some other RuntimeException... throw new HibernateException("illegally attempted to associate a proxy with two open Sessions"); } else { session = s; } } }
protected final boolean isConnectedToSession() { return session!=null && session.isOpen() && session.getPersistenceContext().containsProxy(this); }
/** * Is the collection currently connected to an open session? */ private final boolean isConnectedToSession() { return session!=null && session.isOpen() && session.getPersistenceContext().containsCollection(this); }
public final void initialize() throws HibernateException { if (target==null) { if ( session==null ) { throw new LazyInitializationException("could not initialize proxy - no Session"); } else if ( !session.isOpen() ) { throw new LazyInitializationException("could not initialize proxy - the owning Session was closed"); } else if ( !session.isConnected() ) { throw new LazyInitializationException("could not initialize proxy - the owning Session is disconnected"); } else { target = session.immediateLoad(entityName, id); } } }
private Object intercept(Object target, String fieldName, Object value) { if ( initializing ) return value; if ( uninitializedFields != null && uninitializedFields.contains( fieldName ) ) { if ( session == null ) { throw new LazyInitializationException( "entity with lazy properties is not associated with a session" ); } else if ( !session.isOpen() || !session.isConnected() ) { throw new LazyInitializationException( "session is not connected" ); } final Object result; initializing = true; try { result = ( ( LazyPropertyInitializer ) session.getFactory().getEntityPersister( entityName ) ) .initializeLazyProperty( fieldName, target, session ); } finally { initializing = false; } uninitializedFields = null; //let's assume that there is only one lazy fetch group, for now! return result; } else { return value; } }
protected final Object intercept(Object target, String fieldName, Object value) { if ( initializing ) { return value; } if ( uninitializedFields != null && uninitializedFields.contains( fieldName ) ) { if ( session == null ) { throw new LazyInitializationException( "entity with lazy properties is not associated with a session" ); } else if ( !session.isOpen() || !session.isConnected() ) { throw new LazyInitializationException( "session is not connected" ); } final Object result; initializing = true; try { result = ( ( LazyPropertyInitializer ) session.getFactory() .getEntityPersister( entityName ) ) .initializeLazyProperty( fieldName, target, session ); } finally { initializing = false; } uninitializedFields = null; //let's assume that there is only one lazy fetch group, for now! return result; } else { return value; } }
public final void initialize() throws HibernateException { if (!initialized) { if ( session==null ) { throw new LazyInitializationException("could not initialize proxy - no Session"); } else if ( !session.isOpen() ) { throw new LazyInitializationException("could not initialize proxy - the owning Session was closed"); } else if ( !session.isConnected() ) { throw new LazyInitializationException("could not initialize proxy - the owning Session is disconnected"); } else { target = session.immediateLoad(entityName, id); initialized = true; checkTargetState(); } } else { checkTargetState(); } }
LazyInitializer initializer = proxy.getHibernateLazyInitializer(); SessionImplementor implementor = initializer.getSession(); if (implementor.isOpen())
private Object getReplacement() { final SessionImplementor session = getSession(); if ( isUninitialized() && session != null && session.isOpen()) { final EntityKey key = new EntityKey( getIdentifier(), session.getFactory().getEntityPersister( getEntityName() ), session.getEntityMode() ); final Object entity = session.getPersistenceContext().getEntity(key); if (entity!=null) setImplementation( entity ); } if ( isUninitialized() ) { if (replacement==null) { replacement = serializableProxy(); } return replacement; } else { return getTarget(); } }