"No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here".
I had wired hibernate3.3 with Spring 2.5.2 through annotations on a Spring Web Services project.
I checked the obvious:
1. That I had declared my transaction boundaries using the @Transactional annotation.
2. The Hibernate SessionFactory was being injected as expected.
3. I was using the <tx:annotation-driven /> tag with the default transaction manager.
All were used and created as expected. I was using Spring's <context:component-scan> tag to automatically scan for component (@Component and its derivatives) classes.
I also had two configuration files:
1. (The default) spring-ws-servlet.xml.
2. (A custom) persistence.xml
My <context:component-scan> tag was in the spring-ws-servlet.xml while my <tx:annotation-driven /> tag was in the persistence.xml file. This worked fine if I wired the transactional bean explicitly in the persistence.xml file. After using <context:component-scan > I removed the explicit declaration. Following this I got the stated error message. For some reason when annotations were being used to wire the beans, the <tx:annotation-driven /> tag was not "visible" to the beans loaded through annotations. Once I moved the <tx:annotation-driven /> tag to the spring-ws-servlet.xml config file it all worked and the error went away.
<beans ...>
...
<context:component-scan ...>
<tx:annotation-driven />
...
</beans>
It would seem that there is a hierarchy in Spring configuration files. Where those resolved first are visible to those loaded after them and those resolved after are not visible to those resolved before them. I discussed this with a colleague (Dan Everton) who mentioned that Spring has a parent-child relationship when resolving configuration files. "The parent configuration file is like a base class and the child configuration file like a subclass." I assume that the annotation-wired beans are part of the "parent" configuration and are thus visible to all other configurations loaded there after.
I did some hunting around but couldn't find any documentation to support or negate this theory. But using this assumption and moving the <tx:annotation-driven /> tag to the "parent" configuration file made everything work.
If anyone knows how these files are resolved please add a comment.