When I package my classes into WEB-INF/classes the Spring @Transactional methods (or any of the methods that match the point-cut definition) that I have do not take part in a transaction. I am met with lots of 'No Hibernate session found, configuration does not allow...' exceptions in the logs. The puzzling thing is that in the stack trace I can see the CGLIB enhanced class so it does appear to be proxied but a new transaction does not seem to be created.
However if I package the same classes into a jar file and place the jar in WEB-INF/lib, the application works fine! The transaction is created etc., Whats going on here?!? Why doesn't it work when the classes are under WEB-INF/classes?
The Spring transactional configuration is:
I enabled Spring transaction logging and when the app starts up, I can see that:
But when the time comes to actually work in the transactional method, it explodes with exception about not being allowed to create transaction.
Using Spring 3.1.2.
Thanks!
However if I package the same classes into a jar file and place the jar in WEB-INF/lib, the application works fine! The transaction is created etc., Whats going on here?!? Why doesn't it work when the classes are under WEB-INF/classes?
The Spring transactional configuration is:
Code:
<aop:aspectj-autoproxy proxy-target-class="true" /> <context:component-scan base-package="com.example" /> <tx:annotation-driven transaction-manager="txManager"/> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <tx:advice id="serviceAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="save*"/> <tx:method name="update*"/> <tx:method name="delete*"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="servicePointcut" expression="execution(* com.example.service.*.*Service*.*(..))"/> <aop:advisor advice-ref="serviceAdvice" pointcut-ref="servicePointcut"/> </aop:config>
Code:
28 Sep 2012 15:07:16,126 DEBUG NameMatchTransactionAttributeSource:94 - Adding transactional method [save*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT] 28 Sep 2012 15:07:16,133 DEBUG NameMatchTransactionAttributeSource:94 - Adding transactional method [update*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT] 28 Sep 2012 15:07:16,134 DEBUG NameMatchTransactionAttributeSource:94 - Adding transactional method [delete*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT] 28 Sep 2012 15:07:16,136 DEBUG NameMatchTransactionAttributeSource:94 - Adding transactional method[*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly]
Code:
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here] at org.quartz.core.JobRunShell.run(JobRunShell.java:227) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549) Caused by: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63) at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:698)
Thanks!
Comment