Transaction commited too soon!
I'm using Spring with Hibernate and plain JSP (no web framework). I wrapped my service objects with a TransactionInterceptor, but in the JSP, I use a (wrapped) service to obtain an object, the transaction is commited (and its Session closed) before returning from the service object, so when the JSP tries to access the object it gets a "could not initialize proxy - the owning Session was closed" error.
Why is the transaction commited so soon? How can I make the transaction still be open when the JSP is rendering?
Thanks in advance,
Daniel Serodio
Code:
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionTemplate"
class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="autoProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
<value>hibernateInterceptor</value>
</list>
</property>
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="beanNames">
<list>
<value>repositorio*</value>
</list>
</property>
</bean>
<bean id="transactionAttributes"
class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<property name="properties">
<value>
salvar*=PROPAGATION_REQUIRED
buscar*=PROPAGATION_REQUIRED, readOnly
localizar*=PROPAGATION_REQUIRED, readOnly
</value>
</property>
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributeSource">
<ref bean="transactionAttributes" />
</property>
</bean>
<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
<property name="sessionFactory" ref="sessionFactory" />
</bean>