public function loadClassMetadata(LoadClassMetadataEventArgs $args)
    {
        /** @var ClassMetadata $metadata */
        $metadata = $args->getClassMetadata();
        // entity class name
        $className = $metadata->getName();

        // we load repository once per class
        if (in_array($className, $this->classesLoaded)) {
            return;
        }
        $this->classesLoaded[] = $className;

        // a custom repository class must be set and it must be in the repository pool
        if ($metadata->customRepositoryClassName and $this
                ->repositoryPool
                ->has($metadata->customRepositoryClassName)
        ) {
            // load repository from pool (hydrated by the repository compiler pass)
            $repository = $this
                ->repositoryPool
                ->get($metadata->customRepositoryClassName);

            // create entity doctrine repository
            $entityManager = $args->getEntityManager();
            $doctrineRepository = new EntityRepository($entityManager, $entityManager->getClassMetadata($className));

            // hydrate repository with doctrine data
            $repository
                ->setEntityClassName($className)
                ->setObjectManager($entityManager)
                ->setRepository($doctrineRepository)
            ;
        }
    }