final Object proxy = ois.readObject(); if ( proxy instanceof HibernateProxy ) { ( (HibernateProxy) proxy ).getHibernateLazyInitializer().setSession( session ); rtn.proxiesByKey.put( ek, proxy );
/** * Associate a proxy that was instantiated by another session with this session * * @param li The proxy initializer. * @param proxy The proxy to reassociate. */ private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) { if ( li.getSession() != this.getSession() ) { final EntityPersister persister = session.getFactory().getMetamodel().entityPersister( li.getEntityName() ); final EntityKey key = session.generateEntityKey( li.getIdentifier(), persister ); // any earlier proxy takes precedence proxiesByKey.putIfAbsent( key, proxy ); proxy.getHibernateLazyInitializer().setSession( session ); } }
assertTrue( ( (SessionImplementor) s ).isClosed() ); try { ( ( HibernateProxy ) dp ).getHibernateLazyInitializer().setSession( ( SessionImplementor ) s ); fail( "should have failed because session was closed" );
@Override public void setSession(SessionImplementor session) throws HibernateException { this.lazyInitializer.setSession(session); }
/** * Associate a proxy that was instantiated by another session with this session */ private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) throws HibernateException { if ( li.getSession() != this ) { EntityPersister persister = session.getFactory().getEntityPersister( li.getEntityName() ); EntityKey key = new EntityKey( li.getIdentifier(), persister, session.getEntityMode() ); if ( !proxiesByKey.containsKey(key) ) proxiesByKey.put(key, proxy); // any earlier proxy takes precedence proxy.getHibernateLazyInitializer().setSession(session); } }
/** * Associate a proxy that was instantiated by another session with this session */ private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) throws HibernateException { if ( li.getSession() != this ) { EntityPersister persister = session.getFactory().getEntityPersister( li.getEntityName() ); EntityKey key = new EntityKey( li.getIdentifier(), persister, session.getEntityMode() ); if ( !proxiesByKey.containsKey(key) ) proxiesByKey.put(key, proxy); // any earlier proxy takes precedence proxy.getHibernateLazyInitializer().setSession(session); } }
Object proxy = iter.next(); if ( proxy instanceof HibernateProxy ) { ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().setSession( session );
/** * Associate a proxy that was instantiated by another session with this session * * @param li The proxy initializer. * @param proxy The proxy to reassociate. */ private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) { if ( li.getSession() != this.getSession() ) { final EntityPersister persister = session.getFactory().getEntityPersister( li.getEntityName() ); final EntityKey key = session.generateEntityKey( li.getIdentifier(), persister ); // any earlier proxy takes precedence if ( !proxiesByKey.containsKey( key ) ) { proxiesByKey.put( key, proxy ); } proxy.getHibernateLazyInitializer().setSession( session ); } }
/** * Associate a proxy that was instantiated by another session with this session * * @param li The proxy initializer. * @param proxy The proxy to reassociate. */ private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) { if ( li.getSession() != this.getSession() ) { final EntityPersister persister = session.getFactory().getEntityPersister( li.getEntityName() ); final EntityKey key = session.generateEntityKey( li.getIdentifier(), persister ); // any earlier proxy takes precedence if ( !proxiesByKey.containsKey( key ) ) { proxiesByKey.put( key, proxy ); } proxy.getHibernateLazyInitializer().setSession( session ); } }
Object proxy = ois.readObject(); if ( proxy instanceof HibernateProxy ) { ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().setSession( session ); rtn.proxiesByKey.put( ek, proxy ); } else {
Object proxy = ois.readObject(); if ( proxy instanceof HibernateProxy ) { ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().setSession( session ); rtn.proxiesByKey.put( ek, proxy ); } else {
final Object proxy = ois.readObject(); if ( proxy instanceof HibernateProxy ) { ( (HibernateProxy) proxy ).getHibernateLazyInitializer().setSession( session ); rtn.proxiesByKey.put( ek, proxy );
/** * Associate a proxy that was instantiated by another session with this session * * @param li The proxy initializer. * @param proxy The proxy to reassociate. */ private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) { if ( li.getSession() != this.getSession() ) { final EntityTypeDescriptor entityDescriptor = session.getFactory().getMetamodel().findEntityDescriptor( li.getEntityName() ); final EntityKey key = session.generateEntityKey( li.getIdentifier(), entityDescriptor ); // any earlier proxy takes precedence proxiesByKey.putIfAbsent( key, proxy ); proxy.getHibernateLazyInitializer().setSession( session ); } }
if (li.getSession() == null) { try { li.setSession((SessionImplementor) hibernateSession); } catch (Exception ex) { LOG.error(
public void initializeField(final Object parent, final Object field) { if (!Hibernate.isInitialized(field)) { // TODO push this functionality up into // OneTo(One|Many)Transaction.get...() which should // wrap a transaction around all method calls which could hit the // db. // This method may not be running within the scope of a transaction, // so // make sure one is active try { boolean started = startHibernateTransaction(); if (field instanceof PersistentCollection) { HibernateUtil.getCurrentSession().lock(parent, org.hibernate.LockMode.NONE); Hibernate.initialize(field); } else { final LazyInitializer lazy = ((HibernateProxy) field).getHibernateLazyInitializer(); lazy.setSession((SessionImplementor) HibernateUtil.getCurrentSession()); lazy.initialize(); } commitHibernateTransaction(started); LOG.debug("initializeField of type " + field.getClass() + " for parent " + parent); } catch (final RuntimeException e) { HibernateUtil.rollbackTransaction(); throw e; } } }
public NakedObject getAdapterForElseCreateAdapterForTransient(Object object) { // If we have a Hibernate proxy make sure it's initialized, and use the proxied object to look up the // adapter // TODO do we need this in other methods?? if (object instanceof HibernateProxy) { LazyInitializer lazy = ((HibernateProxy) object).getHibernateLazyInitializer(); if (lazy.isUninitialized()) { LOG.info("resolving proxy of type - " + object.getClass()); // This method may not be running within the scope of a transaction, so // make sure one is active NakedObjectsContext.getObjectPersistor().startTransaction(); try { lazy.setSession((SessionImplementor) HibernateUtil.getCurrentSession()); object = lazy.getImplementation(); } catch (RuntimeException e) { NakedObjectsContext.getObjectPersistor().abortTransaction(); throw e; } NakedObjectsContext.getObjectPersistor().endTransaction(); } else { object = lazy.getImplementation(); } } return super.getAdapterForElseCreateAdapterForTransient(object); }
} else { LazyInitializer lazy = ((HibernateProxy) field).getHibernateLazyInitializer(); lazy.setSession((SessionImplementor) session); lazy.initialize();