/*
Factory an entity object with given ID

@param    int                      ID of entity to instantiate
@return   TeamDoe\Core\Something   Entity object
@throws   TeamDoe\Core\Exception   If organization is not found
349067
public static function factory ($id)
    {
        // Which class to instantiate
        $entityClassName = get_called_class();

        // Get object cache registry
        $ObjectRegistry  = \Teon\ObjectRegistry\ObjectRegistry::getInstance();

        // If this object already in cache, use that
        if ($ObjectRegistry->exists($entityClassName, $id)) {
            return $ObjectRegistry->get($entityClassName, $id);
        }

        // If not, instantiate new, store in object registry and return it
        $Object = new $entityClassName($id);
        $ObjectRegistry->store($Object);
        return $Object;
    }
172660
public function newAction($id)
    {
        //get the business entity
        $businessEntity = $this->getBusinessEntity($id);

        /** @var BusinessTemplate $view */
        $view = $this->get('victoire_business_page.BusinessTemplate_chain')->getBusinessTemplate($id);
        $view->setBusinessEntityId($businessEntity->getId());

        $form = $this->createCreateForm($view);

        $parameters = [
            'entity' => $view,
            'form'   => $form->createView(),
        ];

        return new JsonResponse([
            'html' => $this->container->get('templating')->render(
                'VictoireBusinessPageBundle:BusinessTemplate:new.html.twig',
                $parameters
            ),
            'success' => true,
        ]);
    }
803007
public function toModelAttribute($id)
	{
		if ($id === null) {
			$id = self::VALUE_NULL;
		}

		if (! array_key_exists($id,	$this->_map) ) {
			throw new Exception('Conversion from SimpleWorkflow failed : no key found for id = '.$id);
		}
		$value = $this->_map[$id];
		return ($value === self::VALUE_NULL ? null : $value);
	}
789991
function create (entitySpec, id) {
  if (!_.isFunction(entitySpec)) {
    throw new Error(
      `Entity Factory '${id}' should be a function: ${JSON.stringify(
        entitySpec
      )}`
    )
  }

  if (entitySpec.length !== 2) {
    throw new Error(
      `Entity Factory '${id}' method should have an arity of 2, instead got: ${
        entitySpec.length
      }`
    )
  }

  return entitySpec
}
1174148
public function findById($id)
    {
        if (null === ($entity = $this->find($id))) {
            throw RestException::createNotFound($id, $this->getResourceKey(), sprintf(
                'Entity of type `%s` not found.', $this->getClassName()
            ));
        }

        if (!$entity instanceof JsonApiResource) {
            throw RestException::notJsonApiResource($entity);
        }

        return $entity;
    }
936594
public static function get($id)
    {
        /** @var Entity $entity */
        $entity = new static();
        Manager::getInstance()->get($entity)->refreshRelations();
        $className = $entity->getClassName();
        $sql = Sql::createSql($entity->getAdapter())
            ->select($entity->getTableName())
            ->where(
                [
                    "{$entity->getTableName()}.{$entity->_primaryKey} = :id" =>
                        [
                            ':id' => $id
                        ]
                ]
            );
        $events = $entity->getEventManager();
        $event = new Select([
            'sqlQuery' => $sql,
            'params' => compact('id'),
            'action' => Select::GET,
            'singleItem' => true
        ]);
        $events->trigger(Select::BEFORE_SELECT, $entity, $event);
        $row = $event->sqlQuery->first();

        if ($row) {
            $event->data = $row;
            $events->trigger(Select::AFTER_SELECT, $entity, $event);
            $object = new $className($event->data);
            return $object;
        }
        return null;
    }
901397
public function get($id)
    {
        if (!$this->has($id)) {
            $errMsg = sprintf('Failed to get the name of the class nature of the interface %s', $id);
            throw new Exception\ErrorBuildEntityClassNameException($errMsg);
        }

        return $this->entityClassNameCache[$id];
    }
923588
public function getById($id)
    {
        $image = $this->adapter->get(sprintf('%s/images/%d', $this->endpoint, $id));

        $image = json_decode($image);

        return new ImageEntity($image->image);
    }
381621
public DbOrganization getOrganization(final String organizationId) {
        final DbOrganization dbOrganization = repositoryHandler.getOrganization(organizationId);

        if(dbOrganization == null){
            throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
                    .entity("Organization " + organizationId + " does not exist.").build());
        }

        return dbOrganization;
    }
1017196
function (factory, id, context) {
                context = context || this.getContextByProperties();
                return context.createEntity(factory, id);
            }
1001357
public function create($data, $organizationId = null)
    {
        if (isset($organizationId)) {
            return $this->client()->put($data, 'organizations/{organizationId}', ['organizationId' => $organizationId]);
        }

        return $this->client()->post($data, 'organizations');
    }
329879
static function getInstance($id = null)
    {
        $key = empty($id) ? 'default' : $id;
        if (Core::$enableCoroutine)
        {
            return new static($id);
        }
        if (empty(self::$_instances[$key]))
        {
            $object = new static($id);
        }
        else
        {
            $object = self::$_instances[$key];
        }
        return $object;
    }
229042
public function getOrganizationById($orgId)
    {
        $response = $this->doRequest(
            self::RESOURCE_GET_ORGANIZATION,
            [
                'orgId' => $orgId
            ]
        );

        return Organization::fromStream($response);
    }
100622
@Override
    public T findOne(final I id) {
        return inTransaction(new Callable<T>() {
            @Override
            public T call() throws Exception {
                return entityManager.find(entity, id);
            }
        });
    }
1307685
public function getById($id): ?AbstractEntity
    {
        $entity = $this->getRepository()->findById($id);

        if ($entity instanceof AbstractEntity) {
            $this->prepareEntityForGet($entity);
        }

        return $entity;
    }
1045585
public function get($id): QueryEntity
    {
        if ($this->has($id)) {
            return $this->meta[$id];
        }

        throw new RuntimeException("Meta with name \"{$id}\" does not exists.");
    }
210870
public static function create($id = null)
    {
        if ( empty($id) )
        {
            $id = md5(__METHOD__) . count(self::$instances); 
        }
        if ( empty(self::$instances[$id]) )
        {
            self::$instances[$id] = new self();  
        }
        return self::$instances[$id];
    }