Statement-Level Rollback (140)

本文探讨了SQL语句级回滚机制的工作原理。当SQL语句执行过程中出现错误时,该语句的所有效果会被撤销,如同从未执行过一样。文章详细解释了导致语句级回滚的各种情况,包括执行错误、死锁以及语法错误等。

If at any time during execution a SQL statement causes an error, all effects of the
statement are rolled back. The effect of the rollback is as if that statement had never
been run. This operation is a statement-level rollback.
Errors discovered during SQL statement execution cause statement-level rollbacks. An
example of such an error is attempting to insert a duplicate value in a primary key.
Single SQL statements involved in a deadlock (competition for the same data) can also
cause a statement-level rollback. Errors discovered during SQL statement parsing,
such as a syntax error, have not yet been run, so they do not cause a statement-level
rollback.
A SQL statement that fails causes the loss only of any work it would have performed
itself. It does not cause the loss of any work that preceded it in the current transaction. If the
statement is a DDL statement, then the implicit commit that immediately preceded it is
not undone.

语句级回滚
1. SQL语句执行和死锁可造成语句级的回滚
2. SQL失败造成的损失只是它将影响的部分

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10599713/viewspace-980761/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10599713/viewspace-980761/

分析下列log: CookieSpec selected: default Auth cache not set in the context Connection request: [route: {}->http://localhost:8282][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20] Connection leased: [id: 0][route: {}->http://localhost:8282][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20] Opening connection {}->http://localhost:8282 Connecting to localhost/127.0.0.1:8282 Connection established 127.0.0.1:53965<->127.0.0.1:8282 Executing request POST /service HTTP/1.1 Target auth state: UNCHALLENGED Proxy auth state: UNCHALLENGED http-outgoing-0 >> POST /service HTTP/1.1 http-outgoing-0 >> Content-Length: 344 http-outgoing-0 >> Content-Type: text/plain; charset=ISO-8859-1 http-outgoing-0 >> Host: localhost:8282 http-outgoing-0 >> Connection: Keep-Alive http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.6 (Java/10.0.2) http-outgoing-0 >> Accept-Encoding: gzip,deflate http-outgoing-0 >> "POST /service HTTP/1.1[\r][\n]" http-outgoing-0 >> "Content-Length: 344[\r][\n]" http-outgoing-0 >> "Content-Type: text/plain; charset=ISO-8859-1[\r][\n]" http-outgoing-0 >> "Host: localhost:8282[\r][\n]" http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]" http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.6 (Java/10.0.2)[\r][\n]" http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" http-outgoing-0 >> "[\r][\n]" http-outgoing-0 >> "TouLpyQj9s5BjAvFJMMuDXpv8LpAeKWvJkmm3nAhs3eKzfKhwKJ0Y3NQ0a+tXgSBJSj8pCVW7UqsjA/QFNjgY23OCs8bXu/OUY7NSwlUUWDKpRhDjsatT9M5FIDrvKju+Ym8wRctRze6wz/qsLjYDME0zO8VzaBZ+Ym8wRctRzfQUaPMzICud2Jfccv2wW2oVCGxcSWCw4un0flZfOKfqEywysXH0LSZpIM5C9odxulQ7EX3ahH5i/lRl1H4GIXgTndYIMUUxNWQ4Fwa9P/P9sMUMR+2n/lRrd+vDEsllQjI00UXVsc0R5bj2BRCH5bOd0wOqVqsJSKv73KWjd0/5g==" http-outgoing-0 << "HTTP/1.1 200 [\r][\n]" http-outgoing-0 << "Content-Type: text/plain;charset=UTF-8[\r][\n]" http-outgoing-0 << "Content-Length: 88[\r][\n]" http-outgoing-0 << "Date: Fri, 29 Aug 2025 03:22:15 GMT[\r][\n]" http-outgoing-0 << "[\r][\n]" http-outgoing-0 << "c8FtC9s/b2HlIu31nGZ+1kDgnG1nEYgRo9g8CH8xYwvjfUxbNqSafNYgjjVWDpKHCpyNIy7g4wKfhx9q9GFEgA==" http-outgoing-0 << HTTP/1.1 200 http-outgoing-0 << Content-Type: text/plain;charset=UTF-8 http-outgoing-0 << Content-Length: 88 http-outgoing-0 << Date: Fri, 29 Aug 2025 03:22:15 GMT Connection can be kept alive indefinitely Connection [id: 0][route: {}->http://localhost:8282] can be kept alive indefinitely http-outgoing-0: set socket timeout to 0 Connection released: [id: 0][route: {}->http://localhost:8282][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20] Connection manager is shutting down http-outgoing-0: Close connection Connection manager shut down hikariDbPool - configuration: allowPoolSuspension.............false autoCommit......................false catalog.........................none connectionInitSql...............none connectionTestQuery.............none connectionTimeout...............10000 dataSource......................none dataSourceClassName.............none dataSourceJNDI..................none dataSourceProperties............{password=<masked>} driverClassName.................none healthCheckProperties...........{} healthCheckRegistry.............none idleTimeout.....................600000 initializationFailTimeout.......1 isolateInternalQueries..........false jdbcUrl.........................jdbc:oracle:thin:@10.168.1.24:1521/t1rtddev leakDetectionThreshold..........0 maxLifetime.....................1800000 maximumPoolSize.................100 metricRegistry..................none metricsTrackerFactory...........none minimumIdle.....................2 password........................<masked> poolName........................"hikariDbPool" readOnly........................false registerMbeans..................false scheduledExecutor...............none schema..........................none threadFactory...................internal transactionIsolation............default username........................"RTDMGR" validationTimeout...............5000 hikariDbPool - Starting... Loaded driver with class name oracle.jdbc.OracleDriver for jdbcUrl=jdbc:oracle:thin:@10.168.1.24:1521/t1rtddev hikariDbPool - Added connection oracle.jdbc.driver.T4CConnection@372b0d86 hikariDbPool - Start completed. hikariDbPool - Before cleanup stats (total=1, active=1, idle=0, waiting=1) hikariDbPool - After cleanup stats (total=1, active=1, idle=0, waiting=1) hikariDbPool - Added connection oracle.jdbc.driver.T4CConnection@106f9474 hikariDbPool - Added connection oracle.jdbc.driver.T4CConnection@51529e4f hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@106f9474 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@372b0d86 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@106f9474 due to dirty commit state on close(). hikariDbPool - Added connection oracle.jdbc.driver.T4CConnection@6049ea98 hikariDbPool - After adding stats (total=4, active=1, idle=3, waiting=0) hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@372b0d86 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@106f9474 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@372b0d86 due to dirty commit state on close(). Using org.apache.cxf.common.logging.Slf4jLogger for logging. hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@51529e4f due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@106f9474 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@372b0d86 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@372b0d86 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@372b0d86 due to dirty commit state on close(). Using default implementation for ThreadExecutor Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl Quartz Scheduler v.2.3.0 created. RAMJobStore initialized. Scheduler meta-data: Quartz Scheduler (v2.3.0) 'MesJobScheduler' with instanceId 'NON_CLUSTERED' Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally. NOT STARTED. Currently in standby mode. Number of jobs executed: 0 Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 25 threads. Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered. Quartz scheduler 'MesJobScheduler' initialized from an externally provided properties instance. Quartz scheduler version: 2.3.0 Scheduler MesJobScheduler_$_NON_CLUSTERED started. batch acquisition of 0 triggers hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@106f9474 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@372b0d86 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@106f9474 due to dirty commit state on close(). Utilizing schema packaged in local quartz distribution jar. Parsing XML file: D:\WorkSpace\MES\014.RTD_DEV\server\build\quartz\quartz_jobs.xml with systemId: D:\WorkSpace\MES\014.RTD_DEV\server\build\quartz\quartz_jobs.xml Found 1 delete job group commands. Found 1 delete trigger group commands. Found 0 delete job commands. Found 0 delete trigger commands. Directive 'overwrite-existing-data' specified as: true Directive 'ignore-duplicates' specified as: true Found 0 job definitions. Found 0 trigger definitions. Deleting all jobs in ALL groups. Deleting all triggers in ALL groups. Adding 0 jobs, 0 triggers. hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@372b0d86 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@106f9474 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Before cleanup stats (total=4, active=1, idle=3, waiting=0) hikariDbPool - After cleanup stats (total=4, active=1, idle=3, waiting=0) hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). batch acquisition of 0 triggers hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@372b0d86 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Before cleanup stats (total=4, active=0, idle=4, waiting=0) hikariDbPool - After cleanup stats (total=4, active=0, idle=4, waiting=0) batch acquisition of 0 triggers hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@106f9474 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@372b0d86 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). batch acquisition of 0 triggers hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Before cleanup stats (total=4, active=0, idle=4, waiting=0) hikariDbPool - After cleanup stats (total=4, active=0, idle=4, waiting=0) hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@372b0d86 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). batch acquisition of 0 triggers hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Before cleanup stats (total=4, active=0, idle=4, waiting=0) hikariDbPool - After cleanup stats (total=4, active=0, idle=4, waiting=0) hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@106f9474 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@372b0d86 due to dirty commit state on close(). hikariDbPool - Executed rollback on connection oracle.jdbc.driver.T4CConnection@6049ea98 due to dirty commit state on close().
最新发布
08-30
/* * Copyright (c) 2008, 2009, 2011 Oracle, Inc. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 * which accompanies this distribution. The Eclipse Public License is available * at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License * is available at http://www.eclipse.org/org/documents/edl-v10.php. */ package javax.persistence; /** * Lock modes can be specified by means of passing a <code>LockModeType</code> * argument to one of the {@link javax.persistence.EntityManager} methods that take locks * (<code>lock</code>, <code>find</code>, or <code>refresh</code>) or * to the {@link Query#setLockMode Query.setLockMode()} or * {@link TypedQuery#setLockMode TypedQuery.setLockMode()} method. * * <p> Lock modes can be used to specify either optimistic or pessimistic locks. * * <p> Optimistic locks are specified using {@link * LockModeType#OPTIMISTIC LockModeType.OPTIMISTIC} and {@link * LockModeType#OPTIMISTIC_FORCE_INCREMENT * LockModeType.OPTIMISTIC_FORCE_INCREMENT}. The lock mode type * values {@link LockModeType#READ LockModeType.READ} and * {@link LockModeType#WRITE LockModeType.WRITE} are * synonyms of <code>OPTIMISTIC</code> and * <code>OPTIMISTIC_FORCE_INCREMENT</code> respectively. The latter * are to be preferred for new applications. * * <p> The semantics of requesting locks of type * <code>LockModeType.OPTIMISTIC</code> and * <code>LockModeType.OPTIMISTIC_FORCE_INCREMENT<code> are the * following. * * <p> If transaction T1 calls for a lock of type * <code>LockModeType.OPTIMISTIC</code> on a versioned object, * the entity manager must ensure that neither of the following * phenomena can occur: * <ul> * <li> P1 (Dirty read): Transaction T1 modifies a row. * Another transaction T2 then reads that row and obtains * the modified value, before T1 has committed or rolled back. * Transaction T2 eventually commits successfully; it does not * matter whether T1 commits or rolls back and whether it does * so before or after T2 commits. * <li> * </li> P2 (Non-repeatable read): Transaction T1 reads a row. * Another transaction T2 then modifies or deletes that row, * before T1 has committed. Both transactions eventually commit * successfully. * </li> * </ul> * * <p> Lock modes must always prevent the phenomena P1 and P2. * * <p> In addition, calling a lock of type * <code>LockModeType.OPTIMISTIC_FORCE_INCREMENT</code> on a versioned object, * will also force an update (increment) to the entity's version * column. * * <p> The persistence implementation is not required to support * the use of optimistic lock modes on non-versioned objects. When it * cannot support a such lock call, it must throw the {@link * PersistenceException}. * * <p>The lock modes {@link LockModeType#PESSIMISTIC_READ * LockModeType.PESSIMISTIC_READ}, {@link * LockModeType#PESSIMISTIC_WRITE LockModeType.PESSIMISTIC_WRITE}, and * {@link LockModeType#PESSIMISTIC_FORCE_INCREMENT * LockModeType.PESSIMISTIC_FORCE_INCREMENT} are used to immediately * obtain long-term database locks. * * <p> The semantics of requesting locks of type * <code>LockModeType.PESSIMISTIC_READ</code>, <code>LockModeType.PESSIMISTIC_WRITE</code>, and * <code>LockModeType.PESSIMISTIC_FORCE_INCREMENT</code> are the following. * * <p> If transaction T1 calls for a lock of type * <code>LockModeType.PESSIMISTIC_READ</code> or * <code>LockModeType.PESSIMISTIC_WRITE</code> on an object, the entity * manager must ensure that neither of the following phenomena can * occur: * <ul> * <li> P1 (Dirty read): Transaction T1 modifies a * row. Another transaction T2 then reads that row and obtains the * modified value, before T1 has committed or rolled back. * * <li> P2 (Non-repeatable read): Transaction T1 reads a row. Another * transaction T2 then modifies or deletes that row, before T1 has * committed or rolled back. * </ul> * * <p> A lock with <code>LockModeType.PESSIMISTIC_WRITE</code> can be obtained on * an entity instance to force serialization among transactions * attempting to update the entity data. A lock with * <code>LockModeType.PESSIMISTIC_READ</code> can be used to query data using * repeatable-read semantics without the need to reread the data at * the end of the transaction to obtain a lock, and without blocking * other transactions reading the data. A lock with * <code>LockModeType.PESSIMISTIC_WRITE</code> can be used when querying data and * there is a high likelihood of deadlock or update failure among * concurrent updating transactions. * * <p> The persistence implementation must support use of locks of type * <code>LockModeType.PESSIMISTIC_READ</code> * <code>LockModeType.PESSIMISTIC_WRITE</code> on a non-versioned entity as well as * on a versioned entity. * * <p> When the lock cannot be obtained, and the database locking * failure results in transaction-level rollback, the provider must * throw the {@link PessimisticLockException} and ensure that the JTA * transaction or <code>EntityTransaction</code> has been marked for rollback. * * <p> When the lock cannot be obtained, and the database locking * failure results in only statement-level rollback, the provider must * throw the {@link LockTimeoutException} (and must not mark the transaction * for rollback). * * @since Java Persistence 1.0 */ public enum LockModeType { /** * Synonymous with <code>OPTIMISTIC</code>. * <code>OPTIMISTIC</code> is to be preferred for new * applications. * */ READ, /** * Synonymous with <code>OPTIMISTIC_FORCE_INCREMENT</code>. * <code>OPTIMISTIC_FORCE_IMCREMENT</code> is to be preferred for new * applications. * */ WRITE, /** * Optimistic lock. * * @since Java Persistence 2.0 */ OPTIMISTIC, /** * Optimistic lock, with version update. * * @since Java Persistence 2.0 */ OPTIMISTIC_FORCE_INCREMENT, /** * * Pessimistic read lock. * * @since Java Persistence 2.0 */ PESSIMISTIC_READ, /** * Pessimistic write lock. * * @since Java Persistence 2.0 */ PESSIMISTIC_WRITE, /** * Pessimistic write lock, with version update. * * @since Java Persistence 2.0 */ PESSIMISTIC_FORCE_INCREMENT, /** * No lock. * * @since Java Persistence 2.0 */ NONE }
08-07
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值