} else {
descriptor.getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PreUpdateEvent, writeQuery));
}
}
ObjectChangeSet changes = createObjectChangeSet(clone, backUp, changeSet, isNew, unitOfWork, descriptor);
if(changes.hasChanges() && descriptor.hasMappingsPostCalculateChanges() && ! changes.isNew() && ! unitOfWork.getCommitManager().isActive() && !unitOfWork.isNestedUnitOfWork()) {
// if we are in the commit because of an event skip this postCalculateChanges step as we have already executed it.
int size = descriptor.getMappingsPostCalculateChanges().size();
for(int i=0; i < size; i++) {
DatabaseMapping mapping = descriptor.getMappingsPostCalculateChanges().get(i);
org.eclipse.persistence.sessions.changesets.ChangeRecord record = changes.getChangesForAttributeNamed(mapping.getAttributeName());
if(record != null) {
// Deferred attributes will already have been acted on, therefore we need
// to post calculate changes to ensure orphaned objects are removed.
mapping.postCalculateChanges(record, unitOfWork);
}
}
}
//Check if the user set the PK to null and throw an exception (bug# 4569755)
if (changes.getId() == null && !isNew && !changes.isAggregate()) {
if(!(unitOfWork.isNestedUnitOfWork()) || (unitOfWork.isNestedUnitOfWork() && !((UnitOfWorkImpl)unitOfWork.getParent()).isObjectNew(backUp))) {
Object id = descriptor.getObjectBuilder().extractPrimaryKeyFromObject(clone, unitOfWork, false);
throw ValidationException.nullPrimaryKeyInUnitOfWorkClone(clone, id);
}
}
// if forceUpdate or optimistic read locking is on, mark changeSet. This is to force it
// to be stored and used for writing out SQL later on
if ((descriptor.getCMPPolicy() != null) && (descriptor.getCMPPolicy().getForceUpdate())) {
changes.setHasCmpPolicyForcedUpdate(true);
}
if (!changes.hasForcedChangesFromCascadeLocking() && unitOfWork.hasOptimisticReadLockObjects()) {
changes.setShouldModifyVersionField((Boolean)unitOfWork.getOptimisticReadLockObjects().get(clone));
}
if (changes.hasChanges() || changes.hasForcedChanges()) {
return changes;
}
return null;
}