grdhgx 2013-09-03 01:07 采纳率: 0%
浏览 2826

spring+mybatis,事务不起作用,求帮忙

spring + mybatis,开始annotation式事务
配置如下:









<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
     <property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />

在Service层使用@Transactional,Service没有用接口
@Transactional
public void registerAccount(Account account, String email, Long classId) {
try {
addAccount(account);
AccountDetail accountDetail = new AccountDetail(accountId);
accountDetail.setEmail(email.trim());
addAccountDetail(accountDetail);
addAccountToClass(accountId, classId);
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage());
}
}

三个add*方法都是private方法,没有try catch块。当addAccountToClass方法抛错时,会在当前这个try catch块中被捕获,并抛出RuntimeException。但是,前面的两个add方法却没有回滚,谁知道是怎么回事?

log日志如下:
[DEBUG] 2013-09-03 08:51:48 :ooo Using Connection [jdbc:mysql://localhost:3306/test, UserName=root@localhost , MySQL-AB JDBC Driver]
[DEBUG] 2013-09-03 08:51:48 :==> Preparing: select * from account where name = ?;
[DEBUG] 2013-09-03 08:51:48 :==> Parameters: uuux(String)
[DEBUG] 2013-09-03 08:51:48 :ooo Using Connection [jdbc:mysql://localhost:3306/test, UserName=root@localhost , MySQL-AB JDBC Driver]
[DEBUG] 2013-09-03 08:51:48 :==> Preparing: insert into tbl_account (password, name, gender) values (?, ?, ?);
[DEBUG] 2013-09-03 08:51:48 :==> Parameters: 81dc9bdb52d04dc20036dbd8313ed055(String), uuux(String), 0(Integer)
[INFO ] 2013-09-03 08:51:48 :创建新用户uuux
[DEBUG] 2013-09-03 08:51:48 :ooo Using Connection [jdbc:mysql://localhost:3306/test, UserName=root@localhost , MySQL-AB JDBC Driver]
[DEBUG] 2013-09-03 08:51:48 :==> Preparing: insert into tbl_account_detail (account_id, email, age) values (?, ?, ?);
[DEBUG] 2013-09-03 08:51:48 :==> Parameters: 20(Long), ds@s.s(String), null
[INFO ] 2013-09-03 08:51:48 :创建新用户详情
[DEBUG] 2013-09-03 08:51:48 :ooo Using Connection [jdbc:mysql://localhost:3306/test, UserName=root@localhost , MySQL-AB JDBC Driver]
[DEBUG] 2013-09-03 08:51:48 :==> Preparing: insert into tbl_account_class_ref (account_id, class_id) values (accountId, ?);
[DEBUG] 2013-09-03 08:51:48 :==> Parameters: 1(Long)
[INFO ] 2013-09-03 08:51:48 :Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
[INFO ] 2013-09-03 08:51:48 :SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
[ERROR] 2013-09-03 08:51:48 :

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'accountId' in 'field list'

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: insert into tbl_account_class_ref (account_id, class_id) values (accountId, ?);

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'accountId' in 'field list'

这里我觉得比较奇怪的一点事:日志中打印了多个ooo Using Connection [jdbc:mysql://localhost:3306/test,... 是不是意味着每个操作都用了一个单独的连接?

  • 写回答

1条回答

  • 绝版男子 2013-09-30 07:28
    关注

    可以把每个connection对象都打印一下看看,就知道是不是单独的了。

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料