Announcement Announcement Module
No announcement yet.
@Service conflicts with @Transactional in Tomcat Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Service conflicts with @Transactional in Tomcat

    I have a service with methods marked as Transactional on a product that has worked for almost a year. I tried replacing the XML bean declaration with a Service annotation at the top of the class, and it seemed to work fine. Unit tests on the transactional methods work, however when I call the exact same methods within Tomcat 6.0, I get a LazyInitializationException (while iterating through a lazy collection), indicating that the session (and thus the transaction) is not being preserved. When I remove the component annotation and declare the bean in XML again, it works fine. Any ideas?

  • #2
    One more thing. I tried setting the "order" attribute in my tx:annotation-driven tag to 1, 200, and 1000000, and that didn't change the behavior either.


    • #3
      Do you have something like this in your spring xml config:

       <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
              <property name="sessionFactory" ref="sessionFactory"/>
          <tx:annotation-driven transaction-manager="txManager"/>
          <context:annotation-config />
          <context:component-scan base-package="com.yourcompany.yourproject"/>


      • #4
        Hi guys,

        I posted this as a comment to Solomon's blog post as well:

        Hi Solomon,

        I'm using @Service in combination with @Transactional all the time, but not on Tomcat, so I currently can't really figure out what's going wrong with your setup. Could you provide a bit more information in a JIRA issue (ideally a stripped-down WAR file that we can deploy showing the issue) so that we can start researching a little bit more?

        JIRA is the best place for issues like those...