- 浏览: 167899 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
ooo456mmm:
正解~~~
无需安装oracle,配置plsql developer -
tjuking:
帮我解决了一大问题,thx~
vim批量修改文件 解决 非法字符: \65279 问题 -
dou85dou:
where is lz's content?
如何打造Linux下的IDE
zz from :
http://www.codeinstructions.com/2009/04/read-only-transactions-with-spring-and.html
Read-Only transactions with Spring and Hibernate
Spring supports the concept of read-only transactions. Because Spring
doesn't provide persistence functionality itself, the semantics of
read-only transactions depend on the underlying persistence framework
used along with Spring.
I use Spring with Hibernate and Oracle,
and when I looked to understand the semantics of read-only transactions
on this specific configuration, I found that there was very little
information on the web. The existing information is scarce and not very
clear, and as a result I had to do some research myself, which included
hacking into Spring and Hibernate's source code. Not that I don't
enjoy spending a few late hours reading good code, but so that you don't
have to do it yourself, here is what I found.
Spring
Spring's documentation doesn't say almost anything about what a read-only transaction really means. The best information
I could find was:
Read-only
status: a read-only transaction does not modify any data. Read-only
transactions can be a useful optimization in some cases (such as when
using Hibernate).
That's basically all it says. Google and a little hacking shed some light on the real meaning of the sentence above: 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
. Now lets understand what it means and what are the implications in a Hibernate/Oracle setup.
Hibernate
Hibernate
doesn't have the concept of read-only sessions. But when a session's
flush mode is set to FLUSH_NEVER, which is what Spring does, two
interesting things happen. First, running HQL queries no longer cause
Hibernate to flush the session state to the database, which can provide a
dramatic performance improvement. Secondly, Hibernate will not flush
the changes before commiting the transaction. But the user can still
call Session.flush() by hand, causing any modifications to be persisted
to database. This is where Spring's call to Connection.setReadOnly()
comes handy.
Oracle
When
using the Oracle JDBC driver, calling connection.setReadOnly(true)
translates into the statement "SET TRANSACTION READ ONLY". This
statement limits the types of SQL statements that can be executed during
the transaction. Only SELECTS (without 'FOR UPDATE') and a few other
statements can be executed. Specifically, no UPDATEs, DELETEs, INSERTs
or MERGEs can be executed. This behavior is Oracle-specific. Other
RDBMS can have different semantics for read only transactions or simply
not support it at all.
By setting the JDBC connection to
read-only, Spring prevents a distracted user from persisting changes by
flushing the Hibernate session to the database.
Notes
As
we saw, with the two measures taken by Spring, the transaction is
guaranteed to be read-only through the JDBC connection, and performance
improvements are obtained by setting the Hibernate session to
FLUSH_NEVER.
There is one thing that doesn't happen, though.
Even during Spring read-only transactions, Hibernate queries still save
the state of persistent objects in the session cache. In theory it
wouldn't be necessary, since this state is used to detect modifications
during session flushes. Depeding on the size and number of objects it
can make a huge difference in terms of memory usage.
If you
still want to prevent Hibernate from saving the object state in the
session cache, you have to manually run the HQL queries in read-only
mode. It would be a nice improvement to Hibernate to have a read-only
mode to the session so that no object state is stored and no flush
executed.
发表评论
-
c++与java内存模型& c++ vTable
2012-11-03 16:25 1012参见: http://stackoverflow.com/q ... -
maven pom 指南
2012-11-03 15:56 780http://maven.apache.org/pom.htm ... -
could not discover transaction status
2012-11-01 18:08 1021https://community.jboss.org/thr ... -
zz java 类初始化顺序
2012-08-17 14:42 719zz from http://ig2net.info/arch ... -
JSP JSF tag关系
2012-07-12 23:44 940zz from http://drewdev.blogspot ... -
class泛型反射相关API介绍
2012-06-21 10:49 868class泛型反射相关API介绍: 1. getGeneri ... -
服务提供者框架(Service provider framework)
2012-06-14 16:55 1123服务提供者框架(Service provider framew ... -
JMS的使用
2012-05-30 16:24 9601. 何时使用MQ 如果仅仅是为了达到异步调用的目的, ... -
java EE 6 中Jsf 2.0 managedBean和CDI关系
2012-05-29 15:55 2764转自 :http://stackoverflow.com/qu ... -
maven 默认编码
2012-05-28 15:59 5430maven会使用平台的默认编码,中文系统就是GBK 如果使用 ... -
Seam的事务管理
2012-05-17 17:10 1158Seam的事务管理 Seam和jsf绑定在一起,seam将j ... -
seam与jsf的结合
2012-04-10 23:02 881Seam与JSF的结合 1. 采用org.jboss.seam ... -
maven依赖之optional
2012-04-09 15:42 898http://maven.apache.org/guides/ ... -
Visualsvn+trac 0.12 配置
2012-03-13 09:54 947主要参考了: http://www.cnblogs.com/ ... -
seam 的interceptor分析
2012-03-12 10:36 10251. componet.initialInstance()的时 ... -
zzEJB sessionBean的生命周期
2012-02-29 22:18 832【译】 Stateless Session Be ... -
关于jboss 4 的JNDIVIew 名字空间
2012-02-27 18:11 1042Jboss JNDI http://do ... -
多个EJB entity jar 使用同一个 persistence.xml
2012-02-22 18:32 750可以利用 persistence.xml 的 class、ma ... -
java的ClassLoader机制
2012-02-22 16:27 867zz from :http://www.cnblogs.com ... -
hibernate 分页
2011-11-01 09:10 674setFirstResult 是起始数据,setMaxResu ...
相关推荐
赠送jar包:hibernate-jpa-2.1-api-1.0.2.Final.jar; 赠送原API文档:hibernate-jpa-2.1-api-1.0.2.Final-javadoc.jar; 赠送源代码:hibernate-jpa-2.1-api-1.0.2.Final-sources.jar; 赠送Maven依赖信息文件:...
赠送jar包:hibernate-jpa-2.1-api-1.0.2.Final.jar; 赠送原API文档:hibernate-jpa-2.1-api-1.0.2.Final-javadoc.jar; 赠送源代码:hibernate-jpa-2.1-api-1.0.2.Final-sources.jar; 赠送Maven依赖信息文件:...
hibernate-jpa-2.1-api-1.0.0.final-sources.jar 源码 hibernate-jpa-2.1-api-1.0.0.final-sources.jar 源码
hibernate-jpa-2.0-api-1.0.1.Final-sources.jar hibernate jpa 源代码
hibernate-jpa-2.0-api-1.0.1.Final.jar
`hibernate-jpa-2.1-api-1.0.0.final.jar`是Hibernate对JPA 2.1规范的实现库,它使得开发者能够使用Hibernate的高效功能同时遵循JPA规范。 **1. Hibernate与JPA的关系** Hibernate最初作为一个独立的ORM框架,后来...
hibernate-jpa-2.1-api-1.0.0.Final.jar官方下载,请放心使用
jpa--7.api(EntityManager其他方法)jpa--7.api(EntityManager其他方法)jpa--7.api(EntityManager其他方法)jpa--7.api(EntityManager其他方法)
jpa--6.api(EntityManager实体的状态)jpa--6.api(EntityManager实体的状态)jpa--6.api(EntityManager实体的状态)jpa--6.api(EntityManager实体的状态)
### OpenJPA-Manual 关键知识点解析 #### 一、OpenJPA介绍 **1.1 关于本文档** 本文档旨在提供一个全面且深入的指南,帮助开发人员理解和掌握Java Persistence API(JPA)的核心概念及其在Apache OpenJPA中的实现...
java.lang.NoClassDefFoundError: javax/persistence/spi/ProviderUtil 或javax/persistence/entitylistener问题
java运行依赖jar包
【标题】"myfaces-extcdi-jpa1-module-impl-1.0.6.zip" 涉及的是一款开源项目中的模块实现,主要关注MyFaces扩展CDI(Contexts and Dependency Injection)与JPA(Java Persistence API)的集成。MyFaces是Apache...
《Querydsl-JPA-Codegen 3.3.3与JBugmenot开源项目解析》 在IT领域,开源项目是推动技术发展的重要力量。本文将深入探讨两个相关的开源项目——"querydsl-jpa-codegen-3.3.3.zip" 和 "JBugmenot.zip",它们分别在...
本篇文章将重点围绕“hibernate-jpa-2.1-api-1.0.0.final-sources.jar.zip”这一压缩包,深入解析Hibernate对JPA 2.1 API的实现,以期帮助读者深入理解其内部机制。 JPA(Java Persistence API)是Java平台上的一个...
这个源码包"hibernate-jpa-2.0-api-1.0.1.Final-sources"包含了完整的源代码,可以帮助我们深入了解其内部机制,从而更好地应用在实际项目中。 1. **JPA简介**:Java Persistence API(JPA)是Java平台上的一个标准...
赠送jar包:spring-data-jpa-2.0.9.RELEASE.jar; 赠送原API文档:spring-data-jpa-2.0.9.RELEASE-javadoc.jar; 赠送源代码:spring-data-jpa-2.0.9.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-data-jpa...