Results 1 to 9 of 9

Thread: set transaction manager for IBATIS

  1. #1
    Join Date
    Sep 2004
    Posts
    20

    Default set transaction manager for IBATIS

    How do i set the transaction manager for my datasource when using IBATIS + Spring? Does it need to be in code or just my applicationContext?

    Thanks,
    David

  2. #2
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    You can define a org.springframework.jdbc.datasource.DataSourceTran sactionManager for your DataSource. SqlMapTemplate and SqlMapClientTemplate will automatically participate in such transactions, just like JdbcTemplate does.

    Juergen

  3. #3
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    Have a look at the sample applications (for example, Petclinic or imagedb) that come with the Spring distribution, regarding how to set up transactional proxies. Essentially, you'll need a TransactionProxyFactoryBean per service, automatically executing specific methods in transactions.

    Juergen

  4. #4
    Join Date
    Sep 2004
    Posts
    20

    Default

    I have looked around and am still not sure what i need to do.
    I have added the lines:

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource"><ref local="dataSource"/></property>
    </bean>

    to my applicationContext.xml

    Now what do i do to use it? (I do not hvae anything that requires an explicit start transaction).

    Thanks,
    David

  5. #5
    Join Date
    Sep 2004
    Posts
    20

    Default

    Juergen, what i am asking is, if i have nothing more than inserts to do, do i still need to use the proxyfactorybean?

  6. #6
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    You shouldn't need to execute your data access operations in transactions. In general, it's recommended to proxy your service facades with a TransactionProxyFactoryBean (which is in turn wired with the transaction manager), but that's not required.

    Actually, executing without transactions will just work if you activate default auto-commit in your connection pool. If default auto-commit is turned off, explicit commits are necessary, i.e. explicit transaction demarcation. Maybe you should double-check that.

    Juergen

  7. #7
    Join Date
    Sep 2004
    Posts
    20

    Default

    Yes, I also thought i did not need to execute with transactions. And this is true when i use JNDI or the DriverManagerDataSource. But when i use DBCP, even when i set defaultautocommit to on, the commits are not happening. I think this is related to how IBATIS usese the general transaction manager that is messing me up.

    Thanks,
    Davod

  8. #8
    Join Date
    Sep 2004
    Posts
    20

    Default

    Juergen,

    A simple solution to this would be to add a transasctionManager property to SQLMapClientfactoryBean. This would allow the user to not use Spring transaction management and allow the built in IBATIS transaction managerment to be used instead.
    As a test, I changed the spring code to use the JDBCTransactionConfig instead of the ExternalTransactionConfig and it worked great.
    Would this be an acceptable change to you?

  9. #9
    Join Date
    Sep 2004
    Posts
    20

    Default

    I have now tried to use the transaction manger, and the following lines appear in the log file,

    2004-11-28 12:54:20,953 [main] DEBUG java.sql.PreparedStatement - {pstm-100001} PreparedStatement: INSERT INTO dummy values (SYSDATE)
    2004-11-28 12:54:20,953 [main] DEBUG java.sql.PreparedStatement - {pstm-100001} Parameters: []
    2004-11-28 12:54:20,953 [main] DEBUG java.sql.PreparedStatement - {pstm-100001} Types: []
    2004-11-28 12:54:20,968 [main] DEBUG org.springframework.transaction.interceptor.Transa ctionInterceptor - Invoking commit for transaction on method 'insertRequest' in class [spring.DummyInsert]
    2004-11-28 12:54:20,968 [main] DEBUG org.springframework.jdbc.datasource.DataSourceTran sactionManager - Triggering beforeCommit synchronization
    2004-11-28 12:54:20,968 [main] DEBUG org.springframework.jdbc.datasource.DataSourceTran sactionManager - Triggering beforeCompletion synchronization
    2004-11-28 12:54:20,984 [main] DEBUG org.springframework.jdbc.datasource.DataSourceTran sactionManager - Triggering afterCompletion synchronization
    2004-11-28 12:54:20,984 [main] DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Clearing transaction synchronization


    These would make me think that it works, yet i do not see the commit succeeding.
    Any ideas?

    Thanks,
    David

Similar Threads

  1. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  2. newbie question about custom transaction manager
    By jeroenbreedveld in forum Data
    Replies: 6
    Last Post: Sep 28th, 2005, 11:09 AM
  3. Replies: 0
    Last Post: Jun 6th, 2005, 06:22 AM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Transaction pb Hibernate/MySQL
    By syluser in forum Data
    Replies: 2
    Last Post: Aug 28th, 2004, 02:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •