For entities with attributes that are part of a bidirectional relationship update the other
side of the relationship.

@param entity created or updated entity
@param existingEntity existing entity
9009
public void updateMappedByEntities(
      @Nonnull Entity entity, @Nullable @CheckForNull Entity existingEntity) {
    entity
        .getEntityType()
        .getMappedByAttributes()
        .forEach(
            mappedByAttr -> {
              AttributeType type = mappedByAttr.getDataType();
              if (type != ONE_TO_MANY) {
                throw new RuntimeException(
                    format(
                        "Attribute [%s] of type [%s] can't be mapped by another attribute",
                        mappedByAttr.getName(), type.toString()));
              }
              updateMappedByEntitiesOneToMany(entity, existingEntity, mappedByAttr);
            });
  }
881454
public void addEntityId(long entityId)
    {
        if(this.entityIds == null)
            this.entityIds = new ArrayList<Long>();
        this.entityIds.add(entityId);
    }
944399
private void updateRefEntity(EntityType entityType, Attribute attr, Attribute updatedAttr) {
    if (isSingleReferenceType(attr) && isSingleReferenceType(updatedAttr)) {
      dropForeignKey(entityType, attr);

      if (attr.getRefEntity().getIdAttribute().getDataType()
          != updatedAttr.getRefEntity().getIdAttribute().getDataType()) {
        updateColumnDataType(entityType, updatedAttr);
      }

      createForeignKey(entityType, updatedAttr);
    } else if (isMultipleReferenceType(attr) && isMultipleReferenceType(updatedAttr)) {
      throw new MolgenisDataException(
          format(
              "Updating entity [%s] attribute [%s] referenced entity from [%s] to [%s] not allowed for type [%s]",
              entityType.getId(),
              attr.getName(),
              attr.getRefEntity().getId(),
              updatedAttr.getRefEntity().getId(),
              updatedAttr.getDataType().toString()));
    }
  }
1331357
@Override
    public CreateUpdateEntitiesResult updateEntities(ITypedReferenceableInstance[] entityInstanceDefinitions) throws AtlasException {
        CreateUpdateEntitiesResult result = repository.updateEntities(entityInstanceDefinitions);
        onEntitiesAddedUpdated(result.getEntityResult());
        return result;
    }
518572
public void updateRelationshipIndex(EntityMetadata entityMetadata, GraphDatabaseService graphDb,
            Relationship relationship, MetamodelImpl metaModel)
    {
        if (!isRelationshipAutoIndexingEnabled(graphDb) && entityMetadata.isIndexable())
        {
            Index<Relationship> relationshipIndex = graphDb.index().forRelationships(entityMetadata.getIndexName());

            // Remove all existing relationship entries from Index
            relationshipIndex.remove(relationship);

            // Recreate fresh index on this relationship
            addRelationshipIndex(entityMetadata, relationship, relationshipIndex, metaModel);
        }
    }
782183
@SuppressWarnings("unchecked")
	@Override
	public int update(final Object entity) {
		@SuppressWarnings("rawtypes")
		EntityHandler handler = this.getEntityHandler();
		if (!handler.getEntityType().isInstance(entity)) {
			throw new IllegalArgumentException("Entity type not supported");
		}

		try {
			Class<?> type = entity.getClass();
			TableMetadata metadata = handler.getMetadata(this.transactionManager, type);
			SqlContext context = handler.createUpdateContext(this, metadata, type, true);
			context.setSqlKind(SqlKind.UPDATE);
			handler.setUpdateParams(context, entity);
			int count = handler.doUpdate(this, context, entity);

			if (count == 0 && MappingUtils.getVersionMappingColumn(type).isPresent()) {
				throw new OptimisticLockException(context);
			}
			return count;
		} catch (SQLException e) {
			throw new EntitySqlRuntimeException(SqlKind.UPDATE, e);
		}
	}
287701
private void updateDataType(EntityType entityType, Attribute attr, Attribute updatedAttr) {
    Attribute idAttr = entityType.getIdAttribute();
    if (idAttr != null && idAttr.getName().equals(attr.getName())) {
      throw new MolgenisDataException(
          format(
              "Data type of entity [%s] attribute [%s] cannot be modified, because [%s] is an ID attribute.",
              entityType.getId(), attr.getName(), attr.getName()));
    }

    // do nothing on representation changes XREF --> CATEGORICAL
    if (isSingleReferenceType(attr) && isSingleReferenceType(updatedAttr)) {
      return;
    }

    // do nothing on representation changes MREF --> CATEGORICAL_MREF
    if (isMultipleReferenceType(attr) && isMultipleReferenceType(updatedAttr)) {
      return;
    }

    // remove foreign key on data type updates such as XREF --> STRING
    if (isSingleReferenceType(attr) && !isReferenceType(updatedAttr)) {
      dropForeignKey(entityType, attr);
    }

    if (isSingleReferenceType(attr) && isMultipleReferenceType(updatedAttr)) {
      updateManyToOneToManyToMany(entityType, attr, updatedAttr);
    } else if (isMultipleReferenceType(attr) && isSingleReferenceType(updatedAttr)) {
      updateManyToManyToManyToOne(entityType, attr, updatedAttr);
    } else {
      updateColumnDataType(entityType, updatedAttr);
    }

    // add foreign key on data type updates such as STRING --> XREF
    if (!isReferenceType(attr) && isSingleReferenceType(updatedAttr)) {
      createForeignKey(entityType, updatedAttr);
    }
  }
703503
public function update($entity)
    {
        $eloquentModel = $this->getEloquentModel($entity, true);

        $this->updateRelations($eloquentModel, 'update');

        $eloquentModel->save();

        $eloquentModel->afterSaving($entity, 'update');
    }
1333997
public function addReferencesToEntity($entity)
    {
        foreach ($this->strategies as $strategy) {
            $strategy->addReferencesToEntity($entity);
        }

        $this->objectManager->flush();
    }
532443
protected function update(Entity $entity) {
		$this->updateActiveRow($entity);
		$this->referencesUpdate($entity, $entity->getLoadedReferences());
	}
800544
public void put(Entity entity) {
    EntityType entityType = entity.getEntityType();
    cache.put(
        EntityKey.create(entityType, entity.getIdValue()),
        CacheHit.of(entityHydration.dehydrate(entity)));
  }
670731
private void addToInverseAssociations(
			Tuple resultset,
			int tableIndex,
			Serializable id,
			SharedSessionContractImplementor session) {
		new EntityAssociationUpdater( this )
				.id( id )
				.resultset( resultset )
				.session( session )
				.tableIndex( tableIndex )
				.propertyMightRequireInverseAssociationManagement( propertyMightBeMainSideOfBidirectionalAssociation )
				.addNavigationalInformationForInverseSide();
	}
48196
public int addOrUpdate(Entity entity) throws SQLException {
		return null == entity.get(primaryKeyField) ? add(entity) : update(entity);
	}
69775
public void setEntities(java.util.Collection<AffectedEntity> entities) {
        if (entities == null) {
            this.entities = null;
            return;
        }

        this.entities = new java.util.ArrayList<AffectedEntity>(entities);
    }
1000697
private static void addOrderPossiblyNested(Criteria c, PersistentEntity entity, String sort, String order, boolean ignoreCase) {
        int firstDotPos = sort.indexOf(".");
        if (firstDotPos == -1) {
            addOrder(c, sort, order, ignoreCase);
        } else { // nested property
            String sortHead = sort.substring(0, firstDotPos);
            String sortTail = sort.substring(firstDotPos + 1);
            PersistentProperty property = entity.getPropertyByName(sortHead);
            if (property instanceof Embedded) {
                // embedded objects cannot reference entities (at time of writing), so no more recursion needed
                addOrder(c, sort, order, ignoreCase);
            } else if (property instanceof Association) {
                Association a = (Association) property;
                Criteria subCriteria = c.createCriteria(sortHead);
                PersistentEntity associatedEntity = a.getAssociatedEntity();
                Class<?> propertyTargetClass = associatedEntity.getJavaClass();
                cacheCriteriaByMapping(propertyTargetClass, subCriteria);
                addOrderPossiblyNested(subCriteria, associatedEntity, sortTail, order, ignoreCase); // Recurse on nested sort
            }
        }
    }
877381
public void insertAttributeValueEntity(String attributeName, CmsEntityWrapper value, int index) {

        m_entity.insertAttributeValue(attributeName, value.getEntity(), index);
    }
790527
@Transactional
  @PutMapping("/{entityTypeId}/{id}")
  @ResponseStatus(OK)
  public void update(
      @PathVariable("entityTypeId") String entityTypeId,
      @PathVariable("id") String untypedId,
      @RequestBody Map<String, Object> entityMap) {
    updateInternal(entityTypeId, untypedId, entityMap);
  }