Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Spring TransactionTemplate not rolling back

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am using Spring BatchSqlUpdate to write to 2 different tables.  I wish that if the insert to the second table fails then the insert to the first table should also be rolledback. I tried using TransactionTemplate to achieve the same.  However the same doesnt seem to work . Following is the code and my configuration.

<beans xmlns=""; <br /> xmlns:jdbc=""; <br /> xmlns:xsi=""; <br /> xsi:schemaLocation=" <br /> <br /> <br />">

       <!-- connect to MySQL database -->
<bean id="dataSource" <br /> class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test" />
<property name="username" value="root" />
<property name="password" value="Vallabh" />

<bean id="transactionManager" <br /> class="" />

<bean id = "jdbcTemplate" <br />      class = "org.springframework.jdbc.core.JdbcTemplate">
     <property name = "dataSource" ref = "dataSource" />    
  <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource" ref="dataSource"/>

  <bean id="floatService" class ="">
  <constructor-arg index="0" ref="jdbcTemplate"> </constructor-arg>
  <constructor-arg index="1" ref="transactionManager"> </constructor-arg>


As explained above the insert to the nos table fails since i have made it fail purposely by giving wrong column name. However still the insert to the price table is not rolled back and is commited. What do i to achieve the intended purpose.
Ranch Foreman
Posts: 1898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you see any exception thrown when you insert data to a column that does not exist?
I am not familiar with Spring framework yet. But I guess the data is successfully committed to the price table in one transaction while the transaction for nos table fails.
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic