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:
<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">
<ref bean="transactionManager" />
<ref local="ordersServiceTarget" />
<prop key="*">PROPAGATION_REQUIRED, ISOLATION_DEFAULT</prop>
With debugging turned on, the following message appears in the console output:
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.
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?