ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Meindert" <meind...@pastelebusiness.com>
Subject RE: Transactions with iBatis and Spring
Date Mon, 11 Jun 2007 08:17:06 GMT
Hi Colin,

There is a description for the change from Ibatis DAO on the petstore to the
Spring framework including the transaction handling

Kind Regards

-----Original Message-----
From: Collin Peters [mailto:cadiolis@gmail.com] 
Sent: 09 June 2007 02:15 AM
To: user-java@ibatis.apache.org
Subject: Transactions with iBatis and Spring

I am trying to figure out how transactions work when using Spring and
iBatis.  I am ultimately trying to use transactions at the Spring
level using annotations.  I am very confused about all the different
places for config info.

This is my config BEFORE I tried to implement transactions
    --snip out unrelated code

	<!-- Pooled datasource from JNDI -->
	<jee:jndi-lookup id="dataSource"
		resource-ref="true" />
	<!--  Web SqlMap setup for iBATIS Database Layer -->
	<bean id="dataImportSqlMapConfig"
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation">

	<!-- Define DAO beans-->
	<bean id="dataImportDAOBean"
		<property name="sqlMapClient" ref="dataImportSqlMapConfig"/>

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config
2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
	<sqlMap resource="sqlmaps/DataImport.xml" />

This all worked fine.  Then I changed the configs to the following in
an effort to implement transactions
	<!-- Transaction Manager -->
	<bean id="transactionManager"
		<property name="dataSource" ref="dataSource" />

	<!-- Tell Spring to look for beans annotated for transaction -->

application code
	@Transactional(propagation=Propagation.REQUIRES_NEW, readOnly=false)
	public void runCSVDataImport() throws Exception

Using this code has done *nothing* so I must be missing something.
All the code still executes if it were not in a transaction.  I have
debugged manually by throwing a RuntimeException (unchecked) which
should, as the docs say, implement a rollback.

So I have been trying to get into the iBatis docs to see if anything
additional is required on the iBatis side.  I currently do not have a
<transactionManager> (or nested <dataSource>) element in my iBatis
config.  My first question is "are these elements required when using
Spring transactions?".  I tested by adding it with the following to my
iBatis config:
    <transactionManager type="EXTERNAL">
        <property name="SetAutoCommitAllowed" value="false"/>
        <dataSource type="JNDI">
            <property name="DataSource" value="java:comp/env/jdbc/devel"/>
This did not help matters, and added to my confusion because I could
then remove the dataSource bean from my Spring config which means it
definitely isn't using any of the Spring transaction management stuff.

Are the transactionManager elements from Spring (a bean) and iBatis
(an xml element) mutually exclusive?  If I use the Spring one do I
need one in iBatis?

Please let me know if any other information would help.


View raw message