Read-Only transactions

2017/02/12 iteye

read-only="true|false" 经常出现在Spring事务配置文件或者annotation 属性中,具体解释如下:     1. Spring documents describes:   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). 2. from Google   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.   3. Hiberante   when a session's flush mode is set to FLUSH_NEVER, two 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.   4. 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.       from:  http://www.codeinstructions.com/2009/04/read-only-transactions-with-spring-and.html

Search

    Table of Contents