hc学习平台

 找回密码
 立即注册
搜索
热搜: 活动 交友 javakc
 › 学习交流 › 项目难点 › ssm事务失效
查看: 1964|回复: 2
打印 上一主题 下一主题

ssm事务失效

[复制链接]

5

主题

6

帖子

0

博客

amok

Rank: 9 Rank: 9 Rank: 9

积分

IP 编辑 禁止 帖子 清理

跳转到指定楼层
楼主
发表于2018-12-20 10:17:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

情况一

    事务常用到的实现方式有

  声明型事务

a)   声明型事务通过AOP扫描指定的包结构, , 方法来去实现事务的绑定, 如果设定的方法不在被AOP扫描的范围内, 则会出现事务失效.

  注解型事务

a)   注解型事务是通过在Service逻辑层添加@Transactional来去添加绑定事务, 如果未在指定的方法之上添加则会出现事务失效问题.

情况二

    由private, static, final修饰的方式不能绑定事务, SpringFramework中事务通过Proxy代理来去实现, java中由上述几种类型修饰的方式是不能继承的.

情况三

    SpringMVCSpringIOC重复扫描了Service逻辑层实现类.

    例如:

    在一个SSM的项目中有spring-mvc.xmlspring-mybatis.xml两个配置文件, 两个文件中都扫描到了逻辑层实现类.


5

主题

6

帖子

0

博客

amok

Rank: 9 Rank: 9 Rank: 9

积分

IP 编辑 禁止 帖子 清理

沙发
发表于2018-12-20 17:14:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

spring框架中配置read-only=true/false配置事务的只读

在oracle中配置read-only=true依赖可以执行数据库更新操作.

 Oracle官网:

oracle:10.1

Transaction Isolation Levels and Access Modes

Read-only connections are supported by the Oracle server, but not by the Oracle JDBC drivers.

For transactions, the Oracle server supports only the TRANSACTION_READ_COMMITTED and TRANSACTION_SERIALIZABLE transaction isolation levels. The default is TRANSACTION_READ_COMMITTED. Use the following methods of the oracle.jdbc.OracleConnection interface to get and set the level:

  • getTransactionIsolation(): Gets this connection's current transaction isolation level.

  • setTransactionIsolation(): Changes the transaction isolation level, using one of the TRANSACTION_* values.


oracle:11.1

Transaction Isolation Levels and Access Modes

Read-only connections are supported by the Oracle server, but not by Oracle JDBC drivers.

For transactions, the Oracle server supports only the TRANSACTION_READ_COMMITTED and TRANSACTION_SERIALIZABLE transaction isolation levels. The default is TRANSACTION_READ_COMMITTED. Use the following methods of the oracle.jdbc.OracleConnection interface to get and set the level:

  • getTransactionIsolation: Gets this connection's current transaction isolation level.

  • setTransactionIsolation: Changes the transaction isolation level, using one of the TRANSACTION_* values.


5

主题

6

帖子

0

博客

amok

Rank: 9 Rank: 9 Rank: 9

积分

IP 编辑 禁止 帖子 清理

沙发
发表于2018-12-24 15:18:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

    在最近开发的项目使用的MySQL数据库, 刚开始的使用的时候没有感觉到有什么问题,

后边写了一个几张表同时添加的功能.

    

@Transaction(readOnly=false)
public int insert()
{
	dao1.insert();
	dao2.insert();
	dao3.insert();
}
结果发现不能同时提交或者回滚.


最后定位到了mysql有多个不同的存储引擎, MyISAM,InnoDB...

MySQL是不支持MyISAM引擎的. 需要把引擎修改为InnoDB



站点统计|举报|Archiver|手机版|小黑屋|Comsenz Inc.

GMT+8, , Processed in 0.195171 second(s), 9 queries .

Powered by javakc! X1.0

© 2004-2014 javakc

f1208.com 备案号:京ICP备14030918号-1

返回顶部