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
http://opensource.atlassian.com/confluence/oss/display/IBATIS/Converting+iBA
TIS+DAO+to+Spring+DAO

Kind Regards
 Meindert

-----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
applicationContext.xml
--------------------------------
<beans>
    --snip out unrelated code

	<!-- Pooled datasource from JNDI -->
	<jee:jndi-lookup id="dataSource"
		jndi-name="/jdbc/devel"
		resource-ref="true" />
	
	<!--  Web SqlMap setup for iBATIS Database Layer -->
	<bean id="dataImportSqlMapConfig"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation">
			<value>classpath:dataImportSqlMapConfig.xml</value>
		</property>
	</bean>

	<!-- Define DAO beans-->
	<bean id="dataImportDAOBean"
class="intouch.dataimport.dao.impl.DataImportDAOImpl">
		<property name="sqlMapClient" ref="dataImportSqlMapConfig"/>
	</bean>
</beans>

dataImportSqlMapConfig.xml
-------------------------------------------
<?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">
<sqlMapConfig>
	<sqlMap resource="sqlmaps/DataImport.xml" />
</sqlMapConfig>


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

	<!-- Tell Spring to look for beans annotated for transaction -->
	<tx:annotation-driven/>

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"/>
        </dataSource>
    </transactionManager>
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.

Collin


Mime
View raw message