Results 1 to 3 of 3

Thread: lazy initialization disconnected session problem

  1. #1
    Join Date
    May 2007
    Posts
    6

    Question lazy initialization disconnected session problem

    Hi at all, I've a big problem with lazy initialization of hibernate collections

    When I invoce this method in my DAO service

    public void fullyLoadedRequest(Request request) throws HibernateException {
    getHibernateTemplate().initialize(request.getParam eters());
    getHibernateTemplate().initialize(request.getFinal Actions());
    }

    Spring throws this exception:

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

    I think that the problem is due to different session used to load and to lazy initialize the Request object.... but how could I change this Spring behavior?

    I've configured Spring in this way:

    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="configLocation">
    <value>classpath:etc/hibernate/hibernate.cfg.xml</value>
    </property>
    </bean>

    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager"
    >
    <property name="sessionFactory">
    <ref local="sessionFactory"/>
    </property>
    </bean>

    <bean id="TransactionBean"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean"
    abstract="true">
    <property name="transactionManager">
    <ref local="transactionManager"/>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="login*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    ....


    <bean id="RequestTarget"
    class="it.finmatica.reporservice.service.hibernate .HTRequestService">
    <property name="sessionFactory">
    <ref local="sessionFactory"/>
    </property>
    </bean>

    <bean id="Request" parent="TransactionBean">
    <property name="target">
    <ref local="RequestTarget"/>
    </property>
    </bean>

  2. #2
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    I do it with

    Code:
    getHibernateTemplate().refresh(entity);
    but I don't know if it is appropriate for you as well. Read the Javadoc for the consequences of refresh(..).

    Jörg

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    You might want to have a read of the manual as well.
    http://www.hibernate.org/hib_docs/v3...state-detached
    Last edited by karldmoore; Aug 30th, 2007 at 05:30 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

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