Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 324407

Summary: OptimisticLockException on Update Query when using Batch-Writing on Oracle
Product: z_Archived Reporter: Hans Harz <hansharz_bugzilla>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P2 CC: andrei.ilitchev, douglas.clarke, eclipselink.orm-inbox, gordon.yorke, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Suggested patch. none

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