Persists an entity as part of the current unit of work.

@param object $entity The entity to persist.
559269
public function persist($entity)
    {
        if ($this->evm->hasListeners(Events::prePersist)) {
            $this->evm->dispatchEvent(Events::prePersist, new Event\LifecycleEventArgs($entity, $this->sm));
        }

        $oid = spl_object_hash($entity);
        $this->scheduledForPersist[$oid] = $entity;

        if ($this->evm->hasListeners(Events::postPersist)) {
            $this->evm->dispatchEvent(Events::postPersist, new Event\LifecycleEventArgs($entity, $this->sm));
        }
    }
363168
public function moveAfter($entity)
    {
        if ($this->parent_id == $entity->parent_id) {
            $this->position = $entity->position + 1;
            $this->save();
        } else {
            $this->moveTo($entity->position + 1, $entity->parent_id);
        }
    }
1247893
public function persist(object $entity): self
    {
        $identity = $this->extractIdentity($entity);

        if (!$this->container->contains($identity)) {
            $meta = ($this->metadata)(get_class($entity));
            $this->container->push(
                $identity,
                $entity,
                State::new()
            );
            $this
                ->generators
                ->get($meta->identity()->type())
                ->add($identity);
        }

        return $this;
    }
714041
@Transactional
    public void save(E entity) {
        checkNotNull(entity, "The entity to save cannot be null");

        // creation with auto generated id
        if (!entity.isIdSet()) {
            entityManager.persist(entity);
            return;
        }

        // creation with manually assigned key
        if (jpaUtil.isEntityIdManuallyAssigned(type) && !entityManager.contains(entity)) {
            entityManager.persist(entity);
            return;
        }
        // other cases are update
        // the simple fact to invoke this method, from a service method annotated with @Transactional,
        // does the job (assuming the give entity is present in the persistence context)
    }
1333997
public function addReferencesToEntity($entity)
    {
        foreach ($this->strategies as $strategy) {
            $strategy->addReferencesToEntity($entity);
        }

        $this->objectManager->flush();
    }
1315428
public function push(Entity $entity) {
		$entity->setEntityManager($this->entityManager);
		if ($entity->toRow()) {
			$this->rows[$entity->getPrimary()] = $entity;
		} else {
			$this->rows[] = $entity;
		}
	}
105088
private function persistNew($class, $entity)
    {
        $oid    = spl_object_hash($entity);
        $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::prePersist);

        if ($invoke !== ListenersInvoker::INVOKE_NONE) {
            $this->listenersInvoker->invoke($class, Events::prePersist, $entity, new LifecycleEventArgs($entity, $this->em), $invoke);
        }

        $idGen = $class->idGenerator;

        if ( ! $idGen->isPostInsertGenerator()) {
            $idValue = $idGen->generate($this->em, $entity);

            if ( ! $idGen instanceof \Doctrine\ORM\Id\AssignedGenerator) {
                $idValue = array($class->identifier[0] => $idValue);

                $class->setIdentifierValues($entity, $idValue);
            }

            $this->entityIdentifiers[$oid] = $idValue;
        }

        $this->entityStates[$oid] = self::STATE_MANAGED;

        $this->scheduleForInsert($entity);
    }
416031
public function moveBefore($entity)
    {
        /* @var \Eloquent $this */
        $this->getConnection()->beginTransaction();

        if ($this->position > $entity->position) {
            $this->getConnection()->table($this->getTable())->where('position', '>=', $entity->position)->where(
                'position',
                '<',
                $this->position
            )->increment('position');
            $this->position = $entity->position;

            $entity->position = $entity->position + 1;
        } else {
            if ($this->position < $entity->position) {
                $this->getConnection()->table($this->getTable())->where('position', '<', $entity->position)->where(
                    'position',
                    '>',
                    $this->position
                )->decrement('position');
                $this->position = $entity->position - 1;
            }
        }

        $this->{ $this->getSaveMethod() }();

        $this->getConnection()->commit();
    }
791540
private function handleEntity($entity)
    {
        if (null !== $page = $this->findRelatedPage($entity)) {
            if (null === $page->getId()) {
                return;
            }
            if (!$this->pages->contains($page)) {
                $this->pages->add($page);
            }
        }
    }
812663
public function updateRelations($entity) {
        $mapper = MapperBuilder::buildFromMapping($this->mapping, get_class($entity));
        foreach ($mapper->getRelations() as $relation) {
            if ($relation->getCardinality() == Relation::$manyToMany) {
                // delete previous relations
                $queryDeletePrevious = $this->buildDeleteRelationQuery($relation, $entity);
                $this->conn->executeNonQuery($queryDeletePrevious);

                // insert new relations
                $queryRel = $this->buildRelationQuery($entity);
                foreach (explode(";", $queryRel) as $q) {
                    if (strlen($q) > 5)
                        $this->conn->executeInsert($q);
                }
            }
            if ($relation->getCardinality() == Relation::$oneToMany) {
                $relMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());
                $m = "get" . $relation->getName();
                $setid = "set" . $relMapper->getNameForColumn($relation->getForeignColumn());

                // save actual relations
                foreach ($entity->$m() as $relEntity) {
                    $relEntity->$setid($entity->getId());
                    $this->save($relEntity);
                }

                //  delete old relations.
                // TODO: delete old relations
            }
        }
    }
199911
public function save($entity, $flush = true)
    {
        $this->getEntityManager()->persist($entity);

        if ($flush) {
            $this->getEntityManager()->flush($entity);
        }
        return $this;
    }
632465
public function registerEntity(Entity $entity)
    {
        Logger::get()->debug('Registering entity ' . get_class($entity) . ":{$entity->id}...");
        self::$entities[get_called_class()][$entity->id] = $entity;
        Logger::get()->debug('Registered.');
    }
1154074
public function persist($entity)
    {
        $entityArray = $this->toArray($entity);
        $instance    = $this->getInstanceFromIdentityMap($entity);

        if ($instance) {
            $this->fillExistingInstanceFromEntityArray($instance, $entityArray);
        }
        if (!$instance) {
            $instance = $this->createInstanceFromEntityArray($entityArray);
        }
        $this->persistanceQueue[] = $instance;

        return $this;
    }
699764
protected function save($entities)
    {
        if (!is_array($entities)) {
            $entities = [$entities];
        }

        foreach ($entities as $entity) {
            $entityClass = get_class($entity);
            $entityManager = $this
                ->get('base.object_manager_provider')
                ->getObjectManagerByEntityNamespace($entityClass);
            $entityManager->persist($entity);
            $entityManager->flush($entity);
        }
    }
279742
public function associate($entity)
    {
        $this->parent->setEntityAttribute($this->foreignKey, $entity->getEntityAttribute($this->otherKey));
    }
1167632
public function remove($entity)
    {
        if ( ! is_object($entity)) {
            throw new \InvalidArgumentException(gettype($entity));
        }
        $this->errorIfClosed();
        $this->unitOfWork->remove($entity);
    }
717988
public function saveItem($entity)
    {
        $this->em->persist($entity);
        $this->em->flush();
        return $entity;
    }