I have a pretty simple web application where a Hibernate session is being handled with the OpenSessionInViewInterceptor and everything was working fine.
I needed to add scheduled jobs to the application, so I used the following XML:
(Bear with me, I am in the process of moving to annotations.)
<bean name="myJob" class="com.job.MyJob">
<property name="myDAO" ref="myDAO"/>
<task:scheduled ref="myJob" method="execute" cron="0 26 9 * * ?"/>
Here is my transaction setup:
Before moving to the AOP transaction configuration, my job was throwing an error like "collection is associated with multiple sessions" when I tried to save.
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
<aop:pointcut id="transaction" expression="execution(* com.dao..*.*(..))"/>
<aop:advisor pointcut-ref="transaction" advice-ref="transactionAdvice"/>
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:method name="find*" read-only="true" propagation="SUPPORTS"/>
<tx:method name="save*" read-only="false" propagation="REQUIRED"/>
After moving to the setup above, I now get a "no proxy" error when I try to load properties from a hibernate object.
So, before getting into the details of what the problem might be with my current setup, what is the best way to manage sessions in an application that will simultaneously be accessed via the web and scheduled jobs?
Is it correct to be using the OpenSessionInViewInterceptor (or Filter) in this case?
If my setup does look correct, for the most part, are there any issues that stand out?
Thanks in advance!