protected function _deduplicateResultSet($subject)
    {
        $resultSet = clone $subject->entities;
        $ids = [];
        $keys = (array)$subject->query->getRepository()->getPrimaryKey();
        foreach ($subject->entities as $entity) {
            $id = $entity->extract($keys);
            if (!in_array($id, $ids)) {
                $entities[] = $entity;
                $ids[] = $id;
            }
        }

        if (isset($entities)) {
            $resultSet->unserialize(serialize($entities));
        }

        return $resultSet;
    }