Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 331064 - cannot control delete order with unitofwork deleteobject(object)
Summary: cannot control delete order with unitofwork deleteobject(object)
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-24 16:47 EST by john.vandale CLA
Modified: 2022-06-09 10:23 EDT (History)
3 users (show)

See Also:


Attachments
fix orders deletes by PK sort order if specified in config (7.65 KB, patch)
2010-11-24 17:40 EST, john.vandale CLA
david.minsky: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description john.vandale CLA 2010-11-24 16:47:37 EST
Build Identifier: 

Deadlocks can occur when trying to delete a collection of objects using
uow.deleteObject(objectToBeDeleted). In this reported use case the mapping of this object is one table without any relationship. The primary key is set in all objectToBeDeleted instances.

It is impossible to have a deterministic order for generated
delete SQL. DELETE is executed neither in the order in which the application calls deleteObject or in a PK value ordered fashion.
Deadlocks may occur when concurrent delete/update are executed on the database.

Whether or not a deadlock occurs a non-ordered delete sequence occurs every time.

Reproducible: Sometimes

Steps to Reproduce:
Write an application which deletes objects e.g.:

long[] ids = {800, 801, 802, 803, 804, 805, 806, 807, 808, 809};
UnitOfWork uow = getSession().acquireUnitOfWork();   
uow.setShouldOrderUpdates(true);

for (int i = 0; i < ids.length; i++) {
    Employee employee = new Employee();
    employee.setId(new java.math.BigDecimal(ids[i]));
    Employee registeredEmployee = (Employee) uow.registerExistingObject(employee);
    uow.deleteObject(registeredEmployee);    
   }

uow.commit();

You will see the deletes seem to be in a random order e.g.:

DELETE FROM EMPLOYEE  WHERE (CNT_ID = ?)bind => [804]
DELETE FROM EMPLOYEE  WHERE (CNT_ID = ?)bind => [806]
DELETE FROM EMPLOYEE  WHERE (CNT_ID = ?)bind => [808]
DELETE FROM EMPLOYEE  WHERE (CNT_ID = ?)bind => [807]
DELETE FROM EMPLOYEE  WHERE (CNT_ID = ?)bind => [802]
DELETE FROM EMPLOYEE  WHERE (CNT_ID = ?)bind => [800]
DELETE FROM EMPLOYEE  WHERE (CNT_ID = ?)bind => [803]
DELETE FROM EMPLOYEE  WHERE (CNT_ID = ?)bind => [801]
DELETE FROM EMPLOYEE  WHERE (CNT_ID = ?)bind => [809]
DELETE FROM EMPLOYEE  WHERE (CNT_ID = ?)bind => [805]
Comment 1 john.vandale CLA 2010-11-24 17:40:07 EST
Created attachment 183811 [details]
fix orders deletes by PK sort order if specified in config
Comment 2 David Minsky CLA 2010-11-25 16:02:27 EST
Checked into trunk (2.2) at revision: 8568
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:23:14 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink