Mapping Exception : Class does not exist Symfony2 Deployment

Seif Sayed picture Seif Sayed · Aug 16, 2014 · Viewed 18.4k times · Source

I have a working Project on localhost but when I deployed the project I received this error and I have no idea what's causing this to happen.

 MappingException: Class 'PremiumPharma\SystemBundle\Entity\User' does not exist

this is the stacktrace

in /home/sy2/public_html/temp/symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php line 96
at MappingException::nonExistingClass('PremiumPharma\SystemBundle\Entity\User') in /home/sy2/public_html/temp/symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php line 43
at RuntimeReflectionService->getParentClasses('PremiumPharma\SystemBundle\Entity\User') in /home/sy2/public_html/temp/symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php line 267

Edit 1 I did notice some errors in the profiler as it said 5 invalid entities and there were some mapping errors and I got them fixed. After re-uploading I still have the same issue. I also tried to empty the cache but I still receive the same error.

Edit 2

here is my appKernal

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new PremiumPharma\SystemBundle\PremiumPharmaSystemBundle(),
            new FOS\UserBundle\FOSUserBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }
}

Edit 3

As per J.Mose last comment it was a unix/windows conflict as my local machine was windows and the server was Unix. I had to rename all files to match exactly the classname.

Answer

j-guyon picture j-guyon · Aug 17, 2014

Did you deploy an older version on this environment ?

If yes, did you delete all application's files before deploying ? If an older version of an entity doesn't exist in your project anymore (or renamed), it can provoke that kind of mapping error.

Alternatively, check in your AppKernel.php if the bundle with the entity is enabled on all environnment.

Further, if application is deployed on a Unix environnement (against a local Windows), check if your entity's name is exactly the same as the php file (cause Windows is case insensitive)