Announcement Announcement Module
Collapse
No announcement yet.
Cannot get Spring and EJB to play nicely Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot get Spring and EJB to play nicely

    Having a difficult time getting Spring and EJB to participate in transactions. Even without transactions we have to give Spring-JDBC methods a different datasource than the EJBs else we get deadlocks.

    We have an enterprise application that uses both legacy EJBs (mainly Stateless Session Beans) and Spring beans. The application is deployed on WebSphere 6.1.0.19 and we are currently using Spring 2.0.5.
    In our application the Stateless Session Bean methods are assigned transaction propagation of “Required”. On the Spring beans side, some of the methods have transactional annotations on them and some do not.

    We defined the transaction manager in Spring configuration as below:

    <bean id="wsJtaTm" class="org.springframework.transaction.jta.WebSphe reTransactionManagerFactoryBean" />

    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager">
    <property name="transactionManager" ref="wsJtaTm" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>

    We have a controller that extends org.springframework.web.servlet.mvc.SimpleFormCont roller and in the onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException) method of this Controller we call different Spring and EJB methods.

    Because of the expected high load, we want to make sure that as few connections to the data source as possible are used and hoping that Spring and EJB will be able to reuse connections. To test if the data-source connection is being shared between the EJBs and Spring DAO layer, we have set the maximum connection pool size for the datasource in WebSphere to 1.

    It turns out that Spring and EJB reuse the single connection from the connection pool in some scenarios, but in others they don’t.

    The typical scenario we find where the connections don’t get re-used: we call a spring method without any transaction propagation defined followed immediately by a Stateless Session EJB method call with “required” transaction attribute. The Spring method works fine but the EJB method fails to get connection from the datasource and throws a com.ibm.websphere.ce.cm.ConnectionWaitTimeoutExcep tion: Connection not available, Timed out waiting for 180007 – Exception. On the other hand, if the EJB method follows a Spring method which has transaction propagation defined on it the EJB method is able to reuse the data-source connection.

    We have tried the application with Spring 2.5.6 using org.springframework.transaction.jta.WebSphereUowTr ansactionManager and we see similar behavior. We have also tried the same application on JBoss 5.0.1 and it works with the JtaTransactionManager without any issues with 1 connection.

    Any help is appreciated. We've been wrestling with this for some time. BTW - everything works fine in JBoss 5.
Working...
X