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的更多相关文章

  1. Spring 注解@Transactional readOnly=true

    引子 今天下班后,以前同事小胖问我Spring  Service类中的注解@Transactional readOnly=true的作用.做为他眼中的高人,我自然要装下A-C.居然想都没有想就说是注解 ...

  2. 只读事务@Transactional(readOnly = true)

        定义 从设置的时间点(时间点beta)开始到事务结束的过程中,该事务将看不见其他事务所提交的数据,即查询中不会出现别人在beta之后提交的数据.     应用场合 对于一个函数,如果执行的只是 ...

  3. 只读事务(@Transactional(readOnly = true))的一些概念

    念:从这一点设置的时间点开始(时间点a)到这个事务结束的过程中,其他事务所提交的数据,该事务将看不见!(查询中不会出现别人在时间点a之后提交的数据) 应用场合: 如果你一次执行单条查询语句,则没有必要 ...

  4. Spring的@Transactional(readOnly=true)注解,对其效果进行测试

    https://blog.csdn.net/xcdsdf14545/article/details/86164012

  5. Spring read-only="true" 只读事务的

    概念:从这一点设置的时间点开始(时间点a)到这个事务结束的过程中,其他事务所提交的数据,该事务将看不见!(查询中不会出现别人在时间点a之后提交的数据) 应用场合: 如果你一次执行单条查询语句,则没有必 ...

  6. Spring read-only="true" 只读事务的一些概念

    概念:从这一点设置的时间点开始(时间点a)到这个事务结束的过程中,其他事务所提交的数据,该事务将看不见!(查询中不会出现别人在时间点a之后提交的数据) 应用场合: 如果你一次执行单条查询语句,则没有必 ...

  7. [转载]ASP.NET中TextBox控件设立ReadOnly="true"后台取不到值

    原文地址:http://www.cnblogs.com/yxyht/archive/2013/03/02/2939883.html ASP.NET中TextBox控件设置ReadOnly=" ...

  8. .NET中TextBox控件设置ReadOnly=true后台取不到值的解决方法

    在.NET 2.0 下,当页面上的某个TextBox 设置了属性ReadOnly="True"时,通过客户端脚本给其赋值后,在后台代码中访问其Text属性却无法获得该值.经过尝试, ...

  9. readonly=“readonly”与readonly=“true”

    <input id="u" readonly /> <input id="u" readonly="readonly" / ...

随机推荐

  1. post请求的header

    HTTP Headers 中的 HTTP请求 Accept-Encoding Accept-Encoding: gzip,deflate 大部分的现代浏览器都支持gzip压缩,并会把这一信息报告给服务 ...

  2. 大数据实践:ODI 和 Twitter (二)

    大数据实践:ODI和Twitter(二) 在前面的文章中,我们已经使用flume将数据从twitter抓取到Hive中,现在我们来看看ODI(Oracle Data Integrator)如何在HIV ...

  3. JTAG 引脚自动识别 JTAG Finder, JTAG Pinout Tool, JTAG Pin Finder, JTAG pinout detector, JTAGULATOR, Easy-JTAG, JTAG Enumeration

    JTAG Finder Figuring out the JTAG Pinouts on a Device is usually the most time-consuming and frustra ...

  4. 系统wmiprvse.exe占用CPU非常高,求解决

    1.wmiprvse.exe是微软Windows操作系统的一部分.用于通过WinMgmt.exe程序处理WMI操作.文件位置有二处: C:\WINDOWS\system32\wbem\wmiprvse ...

  5. EBS R12视图打不到数据

    兩個原因引起的,一個是語言,一個是oualter session set nls_language ='AMERICAN';alter session set nls_language='SIMPLI ...

  6. 学习Spring-Session+Redis实现session共享

    1.添加依赖 <dependency> <groupId>org.springframework.session</groupId> <artifactId& ...

  7. Python根据多个空格Split字符串

    下面的String: 1 沪1 上海市 1850 1350 400 1300 1186/1644(嘉定约100,松江69 奉贤68 2007年上海常住人口1858万人,户籍人口1378.86万人,来沪 ...

  8. Json解析包FastJson使用

    阿里巴巴FastJson是一个Json处理工具包,包括“序列化”和“反序列化”两部分,它具备如下特征:速度最快,测试表明,fastjson具有极快的性能,超越任其他的Java Json parser. ...

  9. flex bison

    https://www.gnu.org/software/bison/manual/bison.html https://blog.csdn.net/sirouni2003/article/detai ...

  10. everything结果出现文件找不到

    点击“工具”——“选项”——“索引”——“强制重建”——“确定”, 然后重启everything即可.