Announcement Announcement Module
Collapse
No announcement yet.
Declarative Transaction Woes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Declarative Transaction Woes

    I'm trying to set up an application with declarative transactions using Spring 2 and IBatis and am having no luck. I'd appreciate it if one of the Spring gurus on this board can spot how I screwed up.

    Here's my Spring config file:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    			 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:jee="http://www.springframework.org/schema/jee"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
      
      <bean id="taskService" class="com.corp.app.todolistportlet.database.TaskServiceImpl" >
      	<property name="sqlMap"><ref local="sqlMapClient" /></property>
      </bean>
      
      <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
          <!-- all methods use the default transaction settings -->
          <tx:method name="*" propagation="REQUIRED" />
        </tx:attributes>
      </tx:advice>
      
      <aop:config>
        <aop:pointcut id="allDatabaseServiceMethods" expression="execution(* com.corp.app.todolistportlet.database.TaskService.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="allDatabaseServiceMethods"/>
      </aop:config>
      
      <jee:jndi-lookup id="dataSource" jndi-name="jdbc/todo"></jee:jndi-lookup>
      
      <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
      </bean>
      
      <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
      	<property name="configLocation" value="com/corp/app/todolistportlet/database/sqlMap-config.xml"/>
      	<property name="dataSource" ref="dataSource"/>
      </bean>
      
    </beans>
    and here's my interface TaskService.java:

    Code:
    package com.corp.app.todolistportlet.database;
    
    import java.util.List;
    
    public interface TaskService {
    	List getTasks();
    }
    and my implementation. I'm not using Spring's SqlMapDAOSupport class because I need my service class to extend a different super class:

    Code:
    package com.corp.app.todolistportlet.database;
    
    import java.sql.SQLException;
    import java.util.List;
    
    import org.springframework.orm.ibatis.SqlMapClientCallback;
    
    public class TaskServiceImpl extends TodoListPortletDatabaseService implements TaskService {
    	public List getTasks() {
    		return sqlMap.queryForList("getTasks", null);
    	}	
    }
    When this code is run, the query runs fine, but there's no sign of it getting wrapped by a transaction. My understanding is that the expression
    execution(* com.corp.app.todolistportlet.database.TaskService. *(..))
    should cause each method in the TaskService interface to be wrapped in a transaction. Here's the Spring DEBUG level log output:

    Code:
    [2007-07-02 09:30:33,613] DEBUG (org.springframework.orm.ibatis.SqlMapClientTemplate) - Opened SqlMapSession [com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl@16622e6] for iBATIS operation
    [2007-07-02 09:30:33,613] DEBUG (org.springframework.jdbc.datasource.DataSourceUtils) - Fetching JDBC Connection from DataSource
    [2007-07-02 09:30:33,613] DEBUG (org.springframework.jdbc.datasource.DataSourceUtils) - Fetching JDBC Connection from DataSource
    [2007-07-02 09:30:33,633] DEBUG (java.sql.Connection) - {conn-100000} Connection
    [2007-07-02 09:30:33,633] DEBUG (org.springframework.orm.ibatis.SqlMapClientTemplate) - Obtained JDBC Connection [weblogic.jdbc.wrapper.PoolConnection_oracle_jdbc_driver_OracleConnection@30] for iBATIS operation
    [2007-07-02 09:30:33,644] DEBUG (java.sql.PreparedStatement) - {pstm-100001} PreparedStatement:    SELECT * FROM tasks  
    [2007-07-02 09:30:33,644] DEBUG (java.sql.PreparedStatement) - {pstm-100001} Parameters: []
    [2007-07-02 09:30:33,644] DEBUG (java.sql.PreparedStatement) - {pstm-100001} Types: []
    [2007-07-02 09:30:33,654] DEBUG (java.sql.ResultSet) - {rset-100002} ResultSet
    [2007-07-02 09:30:33,654] DEBUG (java.sql.ResultSet) - {rset-100002} Header: [task_id, task_name, description, date_created]
    [2007-07-02 09:30:33,654] DEBUG (java.sql.ResultSet) - {rset-100002} Result: [2, Update Web Service, Self-explanatory, 2007-07-06]
    [2007-07-02 09:30:33,664] DEBUG (org.springframework.jdbc.datasource.DataSourceUtils) - Returning JDBC Connection to DataSource
    [2007-07-02 09:30:33,664] DEBUG (org.springframework.jdbc.datasource.DataSourceUtils) - Returning JDBC Connection to DataSource
    It's really starting to frustrate me that I can't figure this out, so any help would be greatly appreciated. Thanks in advance!

  • #2
    Same issue

    Your issue is appears similar to the incorrect config I have on anther thread:

    http://forum.springframework.org/showthread.php?t=40794

    I was using BeanFactory but will try the suggested change to ApplicationContext. That might be your issue too.

    Comment


    • #3
      Thanks

      Yes, that was the problem. I was using a BeanFactory instead of an ApplicationContext. Everything works great now. Thanks a lot and I apologize for not noticing that this had been addressed on a previous thread.

      Comment


      • #4
        Originally posted by devilfalcon View Post
        Yes, that was the problem. I was using a BeanFactory instead of an ApplicationContext. Everything works great now. Thanks a lot and I apologize for not noticing that this had been addressed on a previous thread.
        Any chance you could answer the same question I posted on the previous thread? What made you go with BeanFactory?
        Last edited by karldmoore; Aug 29th, 2007, 11:05 AM.

        Comment


        • #5
          Originally posted by karldmoore View Post
          Any chance you could answer the same question I posted on the previous thread? What made you go with BeanFactory?

          Just wild guess from my side - as bean factory is described in the documentation prior to the application context

          Comment


          • #6
            Originally posted by al0 View Post
            Just wild guess from my side - as bean factory is described in the documentation prior to the application context
            Well this is exactly why I asked the question . This is such a common problem then maybe the documentation needs tweaking. That's why I wanted to know if that was indeed the cause.
            Last edited by karldmoore; Aug 29th, 2007, 11:05 AM.

            Comment

            Working...
            X