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

Bug 331064

Summary: cannot control delete order with unitofwork deleteobject(object)
Product: z_Archived Reporter: john.vandale
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: david.minsky, john.vandale, peter.krogh
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
fix orders deletes by PK sort order if specified in config david.minsky: iplog+

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