正反馈和负反馈的区别—SSM框架下的事务回滚问题

pumpkinor 发布于 11/08 16:53
阅读 106
收藏 0

SSM架构下的项目

版本分别是 jdk 8 spring 4.0 mybatis-3.2.7.jar mybatis-spring-1.2.2.jar ojdbc6.jar 

数据库是 oracle 11g

applicationContext.xml 部分的关于事务配置是这样的

<!-- 引入配置文件 -->
	<context:property-placeholder location="classpath:jdbc.properties" />
	<!-- 配置数据源 -->
	<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
		id="dataSource">
		<property name="url" value="${jdbc.url}"></property>
		<property name="driverClassName" value="${jdbc.driverClassName}"></property>
		<property name="username" value="${jdbc.username}"></property>
		<property name="password" value="${jdbc.password}"></property>
	</bean>
	
	<bean id="appTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="dataSource" />
    </bean>
 
    <tx:annotation-driven transaction-manager="appTransactionManager" />

java部分是写了个junit测试:

@RunWith(SpringJUnit4ClassRunner.class)
@TransactionConfiguration(transactionManager = "appTransactionManager", defaultRollback = true)
@Transactional(rollbackFor = Exception.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class GenerateJylshTest {
	@Test
	@Rollback(true)
	public void generateJylshTest() {
	
		String jyjgbh = "4201000000";
		GenerateJylsh generator = new GenerateJylsh();
		int i;
		for(i = 0;i < 3;i++) {
			String jylshString = generator.generateJylsh(jyjgbh);
			System.out.println(jylshString);
		}
		int k = 1/0;
	}
}

控制台结果是:

Creating a new SqlSession
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306]
JDBC Connection [oracle.jdbc.driver.T4CConnection@172b013] will be managed by Spring
==>  Preparing: SELECT * FR吉林福彩快三_信誉网投M BIZ_VEH_IS_TEMP_FL吉林福彩快三_信誉网投WNUM t WHERE t.JCZ = ? AND t.JCXDM = ? 
==> Parameters: 4201000000(String), 42010000001(String)
<==    Columns: JCZ, JCXDM, LSH
<==        Row: 4201000000, 42010000001, 01000019110800027
<==      Total: 1
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306]
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306] from current transaction
==>  Preparing: UPDATE BIZ_VEH_IS_TEMP_FL吉林福彩快三_信誉网投WNUM SET LSH = ? WHERE JCZ = ? AND JCXDM = ? 
==> Parameters: 01000019110800028(String), 4201000000(String), 42010000001(String)
<==    Updates: 1
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306]
01000019110800028
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306] from current transaction
==>  Preparing: SELECT * FR吉林福彩快三_信誉网投M BIZ_VEH_IS_TEMP_FL吉林福彩快三_信誉网投WNUM t WHERE t.JCZ = ? AND t.JCXDM = ? 
==> Parameters: 4201000000(String), 42010000001(String)
<==    Columns: JCZ, JCXDM, LSH
<==        Row: 4201000000, 42010000001, 01000019110800028
<==      Total: 1
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306]
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306] from current transaction
==>  Preparing: UPDATE BIZ_VEH_IS_TEMP_FL吉林福彩快三_信誉网投WNUM SET LSH = ? WHERE JCZ = ? AND JCXDM = ? 
==> Parameters: 01000019110800029(String), 4201000000(String), 42010000001(String)
<==    Updates: 1
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306]
01000019110800029
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306] from current transaction
==>  Preparing: SELECT * FR吉林福彩快三_信誉网投M BIZ_VEH_IS_TEMP_FL吉林福彩快三_信誉网投WNUM t WHERE t.JCZ = ? AND t.JCXDM = ? 
==> Parameters: 4201000000(String), 42010000001(String)
<==    Columns: JCZ, JCXDM, LSH
<==        Row: 4201000000, 42010000001, 01000019110800029
<==      Total: 1
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306]
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306] from current transaction
==>  Preparing: UPDATE BIZ_VEH_IS_TEMP_FL吉林福彩快三_信誉网投WNUM SET LSH = ? WHERE JCZ = ? AND JCXDM = ? 
==> Parameters: 01000019110800030(String), 4201000000(String), 42010000001(String)
<==    Updates: 1
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306]
01000019110800030

Transaction synchronization rolling back SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@c7ba306]



2019-11-08 16:31:09 [main] - [ INF吉林福彩快三_信誉网投 ]  Rolled back transaction after test execution for test context [DefaultTestContext@f316aeb testClass = GenerateJylshTest, testInstance = test.GenerateJylshTest@6aa3a905, testMethod = generateJylshTest@GenerateJylshTest, testException = java.lang.RuntimeException, mergedContextConfiguration = [MergedContextConfiguration@a22cb6a testClass = GenerateJylshTest, locations = '{classpath:applicationContext.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]

2019-11-08 16:31:09 [Thread-1] - [ INF吉林福彩快三_信誉网投 ]  Closing org.springframework.context.support.GenericApplicationContext@4667ae56: startup date [Fri Nov 08 16:31:05 CST 2019]; root of context hierarchy

我本来以为在出现这句结果的时候,

Transaction synchronization rolling back SqlSession 
Transaction synchronization closing SqlSession 

就已经是在抛出异常之后进行了事务的回滚。正反馈和负反馈的区别但是上面的数据却最后还是更新到了数据库,求大神指点可能是哪里有问题。

加载中
返回顶部
顶部