We have a Struts action that calls a service layer to return a lazily loaded Set. The service layer uses declarative transaction management and all our services look the same, aside from the class information:
When we touch the Set from the action, the following error message appears:Code:<bean id="ordersServiceTarget" class="com.service.OrdersServiceImpl" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default"></bean> <bean id="ordersService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default"> <property name="transactionManager"> <ref bean="transactionManager" /> </property> <property name="target"> <ref local="ordersServiceTarget" /> </property> <property name="proxyTargetClass"> <value>true</value> </property> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED, ISOLATION_DEFAULT</prop> </props> </property> </bean>
With debugging turned on, the following message appears in the console output:Code:failed to lazily initialize a collection of role: com.domain.Topic.questions - no session or session was closed
So for some reason, Spring or Hibernate determine that there is no reason to keep the session around.Code:DEBUG [Finalizer] (ConnectionManager.java:369) - running Session.finalize()
However, if the Set is touched in any way, such as a call to isEmpty(), then Session.finalize() never gets called and everything is fine at the action and view layer.
We didn't expect the need to touch the returned collection so I'm wondering if this is expected behavior or did we stumble across a bug?
Thanks,
Chris


Reply With Quote