public function addManaged($entity)
{
$oid = spl_object_hash($entity);
$classMetadata = $this->entityManager->getClassMetadataFor(get_class($entity));
$id = $classMetadata->getIdValue($entity);
if (null === $id) {
throw new \LogicException('Entity marked for managed but could not find identity');
}
$this->entityStates[$oid] = self::STATE_MANAGED;
$this->entityIds[$oid] = $id;
$this->entitiesById[$id] = $entity;
$this->manageEntityReference($oid);
}