Announcement Announcement Module
Collapse
No announcement yet.
lazy initialization disconnected session problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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, 05:30 AM.

      Comment

      Working...
      X