Reputation: 256
<!-- Data source definition -->
<bean id="dataSourceWebsube"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url.websube}"
p:username="${jdbc.username.websube}" p:password="${jdbc.password.websube}" />
<bean id="jdbcTemplateWebsube" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSourceWebsube" />
</bean>
<!-- Transaction manager, actually this one is useless since the Transaction Manager Bean is already called transactionManager -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourceWebsube" />
</bean>
public class Test
{
@Transactional
public static void testTranscational(JdbcTemplate jdbcTmpl)
{
String sql = null;
sql = "INSERT INTO NBSM.INT_RTLNOUTBOUND_PRODUCTS(BASEPRODUCTCODE)VALUES(1)";
jdbcTmpl.update(sql);
throw new RuntimeException();
}
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("application-context.xml");
JdbcTemplate jdbcTmpl = (JdbcTemplate) ctx.getBean("jdbcTemplateWebsube");
testTranscational(jdbcTmpl);
}
}
Hello,
I'm trying to test spring's transaction management capabilities but I cannot get it to work. I have been trying to solve it for hours but no luck.
Above you can see the related config xml definitions and the dao test class. Even when I use debug level for logging, there's no footprint of the rolling back mechanism.
Any help would be greatly appreciated
Upvotes: 1
Views: 3251
Reputation: 120831
It is because of Spring AOP can only:
a) and b) are your faults, you need to fix it. -- to overcome the problem of c) I strongly replace Spring AOP by AspectJ compile time waving.
If I am right, even the transaction handling (by @Transational
must not be working.
Need to be checked by someone else:
I have never seen @Transactional
in combination with JdbcTemplate
, so I have doubt if this is working at all. -- But may I am wrong.
Upvotes: 2