Results 1 to 3 of 3

Thread: Lazyinitialization

  1. #1
    Join Date
    Jun 2006
    Posts
    27

    Default Lazyinitialization

    Hi everybody,
    i want to deliver a objectgraph for my swing app wich is connected over spring http remoting.

    as i dont want to give up the lazy loading performance gains i want to intialize the object graph before sending it to the client.

    I have a Dao that is accessed by the remote server with the following method:
    Code:
    public Catalog getRootCatalog() {
    		Catalog rootCatalog = (Catalog) getHibernateTemplate().get(Catalog.class,new Long(1));
    		getHibernateTemplate().initialize(rootCatalog.getCatalogs());
    		return rootCatalog;
    	}
    The first call getHibernateTemplate().get(Catalog.class,new Long(1)); works without any problems. But when it call getHibernateTemplate().initialize(rootCatalog.getC atalogs());
    i get a lazy initialization exeception:

    org.springframework.orm.hibernate3.HibernateSystem Exception: disconnected session; nested exception is org.hibernate.HibernateException: disconnected session
    org.hibernate.HibernateException: disconnected session

    I use declarative transactions:
    <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean" abstract="true">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="store*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>


    <bean id="trans4" parent="baseTransactionProxy">
    <property name="target" ref="catalogDAO" />
    </bean>


    I also tried to set:
    <prop key="initialize*">PROPAGATION_REQUIRED,readOnly</prop>
    Without any success.

    I would be very happy if someone could help me.

  2. #2
    Join Date
    Jun 2006
    Posts
    27

    Default

    Hi,
    when i use the following code everything works:
    Code:
    public Catalog getRootCatalog() {
    Session session = SessionFactoryUtils.getSession(getSessionFactory(),true);
    		Catalog rootCatalog = (Catalog) session.get(Catalog.class,new Long(1));
    		initializeCatalog(rootCatalog);
    		
    		return rootCatalog;
    	}
    	
    	public void initializeCatalog(Catalog catalog)
    	{
    		Hibernate.initialize(catalog);
    		Hibernate.initialize(catalog.getDocuments());
    		for (Catalog nextCatalog : catalog.getCatalogs()) {
    			initializeCatalog(nextCatalog);
    		}
    	}
    Any hints?

  3. #3
    Join Date
    Oct 2004
    Location
    Herndon, VA, US
    Posts
    648

    Default

    I think somehow the getRootCatalog() method isn't picked up by the transaction proxy, although I can't see from what you posted why not - with "get*" and all.

    You can probably confirm that with this in your second version:
    Code:
    Session session = SessionFactoryUtils.getSession(getSessionFactory(),false);
    --Jing Xue

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •