@Transactional(readOnly=true) in Spring
http://www.skill-guru.com/blog/2010/12/19/transactionalreadonlytrue-in-spring/
@Transactional(readOnly=true) in Spring
What does this mean ?
When a Multi Version Concurrency Control database (Oracle, Postgresql, MySQL + InnoDb) is used, a read only transaction can be translated to the non standard isolation level: READ_ONLY.
The READ_ONLY isolation level provides the same protection as the SERIALIZED isolation level (no dirty reads, no unrepeatable reads, no phantom reads) but doesn’t allow any updates. It also doesn’t cause any lock contention because no locking is required (the database is able to revert back to previous versions of the srecords ignoring all new changes).
Ms Sql 2005 also has a similar isolation level: SNAPSHOT.
If you specify readOnly as true, the flush mode will be set as FlushMode.NEVER in the current Hibernate Session preventing the session from committing the transaction.
Furthermore, setReadOnly(true) will be called on the JDBC Connection, which is also a hint to the underlying database. If your database supports it (most likely it does), this has basically the same effect as FlushMode.NEVER, but it’s stronger since you cannot even flush manually.
Now let’s see how transaction propagation works.
If you don’t explicitly set readOnly to true, you will have read/write transactions. Depending on the transaction attributes (like REQUIRES_NEW), sometimes your transaction is suspended at some point, a new one is started and eventually committed, and after that the first transaction is resumed.
If a method in a read/write transaction calls a method that requires a readOnly transaction, the first one should be suspended, because otherwise a flush/commit would happen at the end of the second method.
Conversely, if you call a method from within a readOnly transaction that requires read/write, again, the first one will be suspended, since it cannot be flushed/committed, and the second method needs that.
In the readOnly-to-readOnly, and the read/write-to-read/write cases the outer transaction doesn’t need to be suspended (unless you specify propagation otherwise, obviously).
@Transactional(readOnly=true) in Spring的更多相关文章
- Spring 注解@Transactional readOnly=true
引子 今天下班后,以前同事小胖问我Spring Service类中的注解@Transactional readOnly=true的作用.做为他眼中的高人,我自然要装下A-C.居然想都没有想就说是注解 ...
- 只读事务@Transactional(readOnly = true)
定义 从设置的时间点(时间点beta)开始到事务结束的过程中,该事务将看不见其他事务所提交的数据,即查询中不会出现别人在beta之后提交的数据. 应用场合 对于一个函数,如果执行的只是 ...
- 只读事务(@Transactional(readOnly = true))的一些概念
念:从这一点设置的时间点开始(时间点a)到这个事务结束的过程中,其他事务所提交的数据,该事务将看不见!(查询中不会出现别人在时间点a之后提交的数据) 应用场合: 如果你一次执行单条查询语句,则没有必要 ...
- Spring的@Transactional(readOnly=true)注解,对其效果进行测试
https://blog.csdn.net/xcdsdf14545/article/details/86164012
- Spring read-only="true" 只读事务的
概念:从这一点设置的时间点开始(时间点a)到这个事务结束的过程中,其他事务所提交的数据,该事务将看不见!(查询中不会出现别人在时间点a之后提交的数据) 应用场合: 如果你一次执行单条查询语句,则没有必 ...
- Spring read-only="true" 只读事务的一些概念
概念:从这一点设置的时间点开始(时间点a)到这个事务结束的过程中,其他事务所提交的数据,该事务将看不见!(查询中不会出现别人在时间点a之后提交的数据) 应用场合: 如果你一次执行单条查询语句,则没有必 ...
- [转载]ASP.NET中TextBox控件设立ReadOnly="true"后台取不到值
原文地址:http://www.cnblogs.com/yxyht/archive/2013/03/02/2939883.html ASP.NET中TextBox控件设置ReadOnly=" ...
- .NET中TextBox控件设置ReadOnly=true后台取不到值的解决方法
在.NET 2.0 下,当页面上的某个TextBox 设置了属性ReadOnly="True"时,通过客户端脚本给其赋值后,在后台代码中访问其Text属性却无法获得该值.经过尝试, ...
- readonly=“readonly”与readonly=“true”
<input id="u" readonly /> <input id="u" readonly="readonly" / ...
随机推荐
- java.sql.SQLException: Error setting driver on UnpooledDataSource.Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for IStudentDaoMapper.Mapperdao.selectcou
是因为 Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for ...
- UML类图的几个名词及对应符号
实现(Implements) 实现的符号为:\(--- \triangleright\) 箭头指向接口. 泛化/继承(Inheritance) 继承的符号为:$ -\triangleright $ 箭 ...
- .net core程序中使用微软的依赖注入框架
我之前在博文中介绍过Asp.net core下系统自带的依赖注入框架,这个依赖框架在Microsoft.Extensions.DependencyInjection中实现,本身并不是.net core ...
- Synchronized、lock、volatile、ThreadLocal、原子性总结、Condition
http://blog.csdn.net/sinat_29621543/article/details/78065062
- Profiling Java Application with Systemtap
https://laurent-leturgez.com/2017/12/22/profiling-java-application-with-systemtap/ https://myaut.git ...
- ios 应用发布渠道大全
#91助手 #同步推 #威锋网 #力美 #PP助手 #同步推线下卖场 #AppleTree #快用苹果助手 #AppleTree-广告 #AppleTree-新市场 #魔品助手ios #itools ...
- mac环境下intellij的自定义配置文件位置
~/Library/Preferences/IntelliJIdea2017.2/
- windows多线程同步互斥--总结
我的windows多线程系列文章: windows多线程--原子操作 windows多线程同步--事件 windows多线程同步--互斥量 windows多线程同步--临界区 windows多线程同步 ...
- O_DIRECT与O_SYNC区别(转)
O_DIRECT和O_SYNC是系统调用open的flag参数.通过指定open的flag参数,以特定的文件描述符打开某一文件. 这两个flag会对写盘的性能有很大的影响,因此对这两个flag做一些详 ...
- 【H5动画】谈谈canvas动画的闪烁问题
一般来说,在H5开发中,使用canvas往往只是为了展示一些简单的图表或者简单短小的动画,很少考虑到有闪烁的问题. 最近,在手机QQ魔法表情的项目中,就遇到了奇葩的闪烁问题. 这里说的闪烁,是指动画刚 ...