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

Bug 319759

Summary: ChangedFieldsLockingPolicy fails for update queries resetting a null value to a non-null value
Product: z_Archived Reporter: David Minsky <david.minsky>
Component: EclipselinkAssignee: David Minsky <david.minsky>
Status: RESOLVED FIXED QA Contact: Project Inbox <eclipselink.foundation-inbox>
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
initial patch for issue
none
Proposed fix and testcase
none
Proposed changes to EL foundation
none
Proposed changes to EL foundation testing
none
Proposed changes to EL foundation
none
Proposed changes to EL foundation testing
none
Proposed changes to EL foundation (v5) none

Description David Minsky CLA 2010-07-13 13:33:09 EDT
1. Using ChangedFieldsLockingPolicy

2. Execute an update where a field is set to null from a non-null value

   UPDATE EMPLOYEE SET GENDER = NULL WHERE ((EMP_ID = 100) AND (GENDER = F))

3. Execute an update where a field is set to a non null value from a null value

The following SQL is executed:

   UPDATE EMPLOYEE SET GENDER = M WHERE ((EMP_ID = 100) AND (GENDER = NULL))

The following exception is seen:

[EL Warning]: UnitOfWork(1801334)--Local Exception Stack: 
Exception [EclipseLink-5006] (Eclipse Persistence Services - 2.2.0.qualifier): org.eclipse.persistence.exceptions.OptimisticLockException
Exception Description: The object [Employee: Jill May] cannot be updated because it has changed or been deleted since it was last read. 
Class> examples.sessions.threetier.model.Employee Primary Key> 2,860
	at org.eclipse.persistence.exceptions.OptimisticLockException.objectChangedSinceLastReadWhenUpdating(OptimisticLockException.java:137)
	at org.eclipse.persistence.descriptors.FieldsLockingPolicy.validateUpdate(FieldsLockingPolicy.java:455)
	at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:1152)
	at org.eclipse.persistence.queries.UpdateObjectQuery.executeCommitWithChangeSet(UpdateObjectQuery.java:84)
	at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:290)
	at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:736)
	at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:643)
	at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)
	at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2909)

The SQL for 2. should be:

   UPDATE EMPLOYEE SET GENDER = M WHERE ((EMP_ID = 100) AND (GENDER IS NULL))

The cached update call from 1. is being re-used in 2. and this results in incorrect SQL for the query parameters (null value) supplied.
Comment 1 David Minsky CLA 2010-07-13 13:44:22 EDT
Created attachment 174186 [details]
initial patch for issue
Comment 2 David Minsky CLA 2010-07-13 18:14:14 EDT
Target is being set to 2.2.0, as the fix would be checked into trunk.
Comment 3 David Minsky CLA 2010-07-14 13:11:36 EDT
Created attachment 174319 [details]
Proposed fix and testcase
Comment 4 David Minsky CLA 2010-07-21 10:54:31 EDT
Created attachment 174861 [details]
Proposed changes to EL foundation
Comment 5 David Minsky CLA 2010-07-21 10:54:53 EDT
Created attachment 174864 [details]
Proposed changes to EL foundation testing
Comment 6 David Minsky CLA 2010-08-24 17:57:34 EDT
Created attachment 177371 [details]
Proposed changes to EL foundation

Foundation changes, including support for other mappings (1:1, 1:M, M:M, Aggregate, V1:1)
Comment 7 David Minsky CLA 2010-08-24 17:58:46 EDT
Created attachment 177372 [details]
Proposed changes to EL foundation testing

Added a new test model and suite to support combined testing for additional mapping and optimistic locking types
Comment 8 David Minsky CLA 2010-08-31 16:38:56 EDT
Created attachment 177891 [details]
Proposed changes to EL foundation (v5)
Comment 9 David Minsky CLA 2010-09-14 18:07:27 EDT
Fixed in revision: 8130
Checked in September 2nd, 2010.
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:03:33 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink