Announcement Announcement Module
Collapse
No announcement yet.
Calling DAOs from a session bean, transaction problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling DAOs from a session bean, transaction problem

    Hi,

    I have a service class (POJO) that uses DAOs to access database.
    Here is the Spring config:

    Code:
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName"><value>java&#58;comp/env/jdbc/ApplicationDS</value></property>
    </bean>
    
    <bean id="projectConfigDAO" class="my.company.ProjectConfigDAOImpl" lazy-init="true">
    <property name="dataSource"><ref local="dataSource"/></property>
    </bean>
    
    <bean id="projectConfigService" class="my.company.ProjectConfigServiceImpl" lazy-init="true">
    <property name="projectConfigDAO"><ref local="projectConfigDAO"/></property>
    </bean>
    And it perfectly works when accessed from a web client.
    But I have a requirement that my services must be exposed as stateless session beans. In fact the 'projectConfigService' is called from a session bean. Methods are just invoked 1:1.
    Transaction attributes on config methods (session bean) are SUPPORTS.

    And it also works from the webclient when I try to invoke it through the session bean.

    The problem starts when the projectConfigEJB is called from another session bean, a method that has REQUIRED as the transaction attribute.
    I simply have deadlock. The other method does sth in database, then calls my config bean - and hangs in this place.

    My guessing would be that I should specify a transaction manager behavior in spring for it.
    1.
    Code:
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
    2.
    Code:
    <bean id="WSTransactionFactory" class="org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean"/> 
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager"><ref local="WSTransactionFactory"/></property>	
    </bean>
    3.
    Code:
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource"><ref local="dataSource"/></property>
    </bean>
    And the service definition is then:

    Code:
    <bean id="projectConfigService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager"><ref local="transactionManager"/></property>
    <property name="target"><ref bean="projectConfigServiceTarget"/></property> <!-- renamed service defined above -->
    <property name="transactionAttributes">
    <props>
    	<prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>
    When I tried option 1 or 2 then it complaints that java:comp/UserTransaction cannot be found in JNDI.

    When I tried 3 then it complaints about the manager trying to work with dataSource commit options directly, which is not allowed.

    It worked before switching to Spring, then I just rewrote 1 DAO, I added the POJO service bean that works on it, and simply redirected calls from the session bean to the POJO service.

    Any hints how I should configure it?
    Is it transaction related problem? probably ...
    Can I invoke such services from inside a session bean?

    I run it in WSAD 5.1, DB2

    Darek

  • #2
    The problem is solved

    My mistake.
    One of the rewritten methods called itself recursively ...
    The problem is solved.

    But it still does not answer why I am unable to get the transaction manager.
    It simply says that java:/comp/UserService is not bound in JNDI, no matter if I configure it the 1st or 2nd way.

    Now it simply works without transaction manager configured on the spring side.

    Comment

    Working...
    X