Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 324407 - OptimisticLockException on Update Query when using Batch-Writing on Oracle
Summary: OptimisticLockException on Update Query when using Batch-Writing on Oracle
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P2 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-03 08:42 EDT by Hans Harz CLA
Modified: 2022-06-09 10:26 EDT (History)
5 users (show)

See Also:


Attachments
Suggested patch. (1.08 KB, patch)
2012-05-15 13:45 EDT, Andrei Ilitchev CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hans Harz CLA 2010-09-03 08:42:48 EDT
Build Identifier: 2.1.1.v20100817-r8050

Investigation shows that there seems to be an inconsistency in how EclipseLink in ParameterizedSQLBatchWritingMechanism computes the number of entities that should be affected by a "batch" query and the number that is returned by the Oracle specific implementation of DatabasePlatform.executeBatch()

Furthermore we notice that of all DatabasePlatform implementations Oracle10Platform is the only one that overrides canBatchWriteWithOptimisticLocking() to return true.

Workaround:
- Either: override Oracle10Platform.canBatchWriteWithOptimisticLocking() to return always false
- Or: (less invasive, but switching off all batch writing) set eclipselink.jdbc.batch-writing to NONE

Notes:
- Our code works fine with many other database backends, e.g. H2, DB2, Postgresql, MS SQL


Reproducible: Always

Steps to Reproduce:
Steps to reproduce: 
- Use Oracle 10 or 11 as backend with the Oracle10Platform
- OptimisticLocking should be active (by default?)
- eclipselink.jdbc.batch-writing is set to JDBC or Oracle-JDBC
- Execute a JPA Query that deletes multiple rows, e.g.
  DELETE FROM MyEntityClass AS c WHERE c.id IN (1, 2, 3, ...)
  with the Query.executeUpdate() method


Result:
- OptimisticLockException is thrown in ParameterizedSQLBatchWritingMechanism.executeBatchedStatements()
with exception description: "One or more objects cannot be updated because it has changed or been deleted since it was last read"
Comment 1 Tom Ware CLA 2010-09-20 09:10:06 EDT
Setting target and priority.  See the following page for details of the
meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 2 Doug Clarke CLA 2011-06-23 07:47:51 EDT
Moving this bug into 2.4 based on the effect I have seen at a customer site. Depending on the complexity of the fix we may want to port to 2.2/2.3 patches.
Comment 3 Andrei Ilitchev CLA 2012-05-15 13:45:15 EDT
Created attachment 215662 [details]
Suggested patch.

It is impossible to enforce optimistic lock for bulk delete, don't set hasOptimisticLock to true.
Comment 4 Andrei Ilitchev CLA 2012-05-15 13:51:50 EDT
Checked the fix into both trunk 2.4 (revision: 11371) and 2.3.3 (revision: 11372)
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:26:08 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink