code: protected void removeUnnecessaryOperations() {
  
          for (Class<? extends Entity> entityClass : deletedObjects.keySet()) {
  
              // Collect ids of deleted entities + remove duplicates
              Set<String> ids = new HashSet<String>();
              Iterator<Entity> entitiesToDeleteIterator = deletedObjects.get(entityClass).values().iterator();
              while (entitiesToDeleteIterator.hasNext()) {
                  Entity entityToDelete = entitiesToDeleteIterator.next();
                  if (!ids.contains(entityToDelete.getId())) {
                      ids.add(entityToDelete.getId());
                  } else {
                      entitiesToDeleteIterator.remove(); // Removing duplicate deletes
                  }
              }
  
              // Now we have the deleted ids, we can remove the inserted objects (as they cancel each other)
              for (String id : ids) {
                  if (insertedObjects.containsKey(entityClass) && insertedObjects.get(entityClass).containsKey(id)) {
                      insertedObjects.get(entityClass).remove(id);
                      deletedObjects.get(entityClass).remove(id);
                  }
              }
          }
      }
docs: Clears all deleted and inserted objects from the cache,
  and removes inserts and deletes that cancel each other.
  <p>
  Also removes deletes with duplicate ids.