public function &getById($type, $id, $use_cache = true)
    {
        $registered_type = $this->requireRegisteredType($type);

        $id = (int) $id;

        if ($id < 1) {
            throw new InvalidArgumentException('ID is expected to be a number larger than 0');
        }

        if (isset($this->objects_pool[$registered_type][$id]) && $use_cache) {
            return $this->objects_pool[$registered_type][$id];
        } else {
            $type_fields = $this->getTypeFields($registered_type);

            if ($row = $this->connection->executeFirstRow($this->getSelectOneByType($registered_type), [$id])) {
                $object_class = in_array('type', $type_fields) ? $row['type'] : $type;

                /** @var object|EntityInterface $object */
                $object = new $object_class($this->connection, $this, $this->log);

                if ($object instanceof ContainerAccessInterface && $this->hasContainer()) {
                    $object->setContainer($this->getContainer());
                }

                $object->loadFromRow($row);

                return $this->addToObjectPool($registered_type, $id, $object);
            } else {
                $object = null;

                return $this->addToObjectPool($registered_type, $id, $object);
            }
        }
    }