概念:从这一点设置的时间点开始(时间点a)到这个事务结束的过程中,其他事务所提交的数据,该事务将看不见!(查询中不会出现别人在时间点a之后提交的数据)
应用场合:
如果你一次执行单条查询语句,则没有必要启用事务支持,数据库默认支持SQL执行期间的读一致性;
如果你一次执行多条查询语句,例如统计查询,报表查询,在这种场景下,多条查询SQL必须保证整体的读一致性,否则,在前条SQL查询之后,后条SQL查询之前,数据被其他用户改变,则该次整体的统计查询将会出现读数据不一致的状态,此时,应该启用事务支持。
【注意是一次执行多次查询来统计某些信息,这时为了保证数据整体的一致性,要用只读事务】
怎样设置:
对于只读查询,可以指定事务类型为readonly,即只读事务。
由于只读事务不存在数据的修改,因此数据库将会为只读事务提供一些优化手段,例如Oracle对于只读事务,不启动回滚段,不记录回滚log。
(1)在JDBC中,指定只读事务的办法为: connection.setReadOnly(true);
(2)在Hibernate中,指定只读事务的办法为: session.setFlushMode(FlushMode.NEVER);
此时,Hibernate也会为只读事务提供Session方面的一些优化手段
(3)在Spring的Hibernate封装中,指定只读事务的办法为: bean配置文件中,prop属性增加“readOnly”
或者用注解方式@Transactional(readOnly=true)
【 if the transaction is marked as read-only, Spring will set the Hibernate Session’s flush mode to FLUSH_NEVER,
and will set the JDBC transaction to read-only】也就是说在Spring中设置只读事务是利用上面两种方式
在将事务设置成只读后,相当于将数据库设置成只读数据库,此时若要进行写的操作,会出现错误
转自: http://blog.csdn.net/MageShuai/article/details/4544191
相关推荐
Spring5 框架 ---- 事务操作 ---- 代码 Spring5 框架 ---- 事务操作 ---- 代码 Spring5 框架 ---- 事务操作 ---- 代码 Spring5 框架 ---- 事务操作 ---- 代码 Spring5 框架 ---- 事务操作 ---- 代码 Spring5 框架 --...
Spring4--3.jdbcTemplate事务
Spring IOC Bean标签属性介绍 0.Bean标签属性介绍 1.0 新建一个Maven工程 1.1 pom.xml 1.2 实体类JavaBean 1.2.1 User类 1.3 当Scope="singleton"时 1.4 当 Scope="singleton" 且 lazy-init="true" 时 1.5 当scope=...
--------------=======Spring 使用技巧========------------------- 1.在SSH中的DAO中执行SQL //申请变量 Connection conn = null; PreparementStatement ps = null; ResultSet rs = null; //通过this.getSession()...
useUnicode=true&characterEncoding=utf-8&useSSL=false spring.datasource.db1.username=root spring.datasource.db1.password=123 spring.datasource.db1.driver-class-name=com.mysql.jdbc.Driver spring....
spring源码缺失jar。spring-cglib-repack-3.2.5.jar,spring-objenesis-repack-2.6.jar
聚合支付使用Java开发,包括spring-cloud、dubbo、spring-boot三个架构版本,已接入微信、支付宝等主流支付渠道,可直接用于生产环境
spring boot 邮件发送,亲测可用 #字符集 spring.mail.default-encoding=UTF-8 #电子邮件地址 spring.mail.host=smtp.126.com #Application spring.application.name=SEND-MAIL #授权密码 spring.mail.password=...
Spring框架-AOP和声明式事务
Spring+iBatis+JOTM实现JTA事务: 如何处理跨库事物:spring + jtom 的jta事务是个很好的选择. ... <tx:method name="*" read-only="true" rollback-for="Exception"/> ...... ...... ......
spring-cglib-repack-3.2.5.jar和spring-objenesis-repack-2.6.jar
<tx:method name="*" read-only="true"/> eclipse出不来自动补齐功能。 要在开头加上这二句: 1.xmlns:tx="http://www.springframework.org/schema/tx" 2....
Spring是一个开放源代码的设计层面框架,他解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿整个系统应用。Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson创建。简单...
Spring-Boot-onlyOffice(集成onlyOffice服务)
将下载的项目手动安装到本地Maven存储库中(-sources和-javadoc文件是可选的): mvn install:install-file \-DpomFile=spring-data-oracle-nosql-x.y.z.pom \-Dfile=spring-data-oracle-nosql-x.y.z.jar \-...
spring-context-3.2.4.RELEASE.jar spring-core-3.2.4.RELEASE.jar spring-beans-3.2.4.RELEASE.jar spring-test-3.2.4.RELEASE.jar spring-web-3.2.4.RELEASE.jar spring-aop-3.2.4.RELEASE.jar spring-webmvc-...
spring.jar spring-aop.jar spring-aop.jar spring-beans.jar spring-hibernate3.jar spring-jdbc.jar spring-struts.jar spring-web.jar
spring-aop-4.1.6.RELEASE.jar spring-aspects-4.1.6.RELEASE.jar spring-beans-4.1.6.RELEASE.jar spring-context-4.1.6.RELEASE.jar spring-context-support-4.1.6.RELEASE.jar spring-core-4.1.6.RELEASE.jar ...
-----------========配置SSH====------------- 1.建立一个web project. 2.添加Spring框架, 2.1 选择Spring 1.2 或者Spring 2.0 2.1.1 选择Spring 1.2 选择jar包,并且把jar放置在/WEB-INF/lib下 select the ...
PostIt是一个基于Spring Boot Web的邮件客户端。 它使用Apache Geode / GemFire中加载的...-name=UserProfile --type=PARTITION_PERSISTENT要读取的配置Geode PDX序列化configure pdx --read-serialized=true --disk