protected function _validateUniqueness(AnConfig $config)
    {
        $property = $config->property;
        $value = $config->value;
        $entity = $config->entity;
        $options = $config->options;
        $conditions = array();

        $query = $entity->getRepository()->getQuery();

        if ($entity->persisted()) {
            $query->where($entity->getEntityDescription()->getIdentityProperty()->getName(), '<>', $entity->getIdentityId());
        }

        $conditions[$property->getName()] = $value;

        if (isset($options['scope'])) {
            $scope = (array) $options['scope'];
            foreach ($scope as $key) {
                $conditions[$key] = $entity->get($key);
            }
        }

        $query->where($conditions);

        if ($query->disableChain()->fetch()) {
            $entity->addError(array(
                'message' => sprintf(
                    AnTranslator::_('%s %s is not unique'),
                    $this->getIdentifier()->name,
                    $property->getName()
                ),
                'code' => AnError::NOT_UNIQUE,
                'key' => $property->getName(),
            ));

            return false;
        }

        return true;
    }