title: Unknown Entity namespace alias 'AppBundle' and "Class 'App\\Entity\\Product' does not exist
body: <p>I'm trying to implement FOSRestBundle so I've just created my first class controller.</p>
  
  <pre><code>    &lt;?php
  
  namespace AppBundle\Controller;
  
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use FOS\RestBundle\Controller\Annotations as Rest;
  use FOS\RestBundle\Controller\FOSRestController;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\HttpFoundation\Response;
  use FOS\RestBundle\View\View;
  use App\Entity\Product;
  
  class ProductController extends FOSRestController
  {
      /**
       * @Rest\Get("/product")
       */
      public function getAction()
      {
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $restresult = $em-&gt;getRepository('AppBundle:Product')-&gt;getAllProduct();
          if ($restresult === null) {
              return new View("there are no products exist", Response::HTTP_NOT_FOUND);
          }
          return $restresult;
      } // "Get products"     [GET] /product*/
  }
  </code></pre>
  
  <p>But Symfony server give me that error: 
  - "Unknown Entity namespace alias 'AppBundle'."
  - "Doctrine\ORM\ORMException";</p>
  
  <p>My composer.json is:</p>
  
  <pre><code>{
      "name": "symfony/framework-standard-edition",
      "license": "MIT",
      "type": "project",
      "description": "The \"Symfony Standard Edition\" distribution",
      "autoload": {
          "psr-4": {
              "AppBundle\\": "src/AppBundle"
          },
          "psr-0": {"": "src/"},
          "classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
      },
      "autoload-dev": {
          "psr-4": { "Tests\\": "tests/" },
          "files": [ "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" ]
      },
      "require": {
          "php": "&gt;=5.5.9",
          "doctrine/doctrine-bundle": "^1.6",
          "doctrine/orm": "^2.5",
          "friendsofsymfony/rest-bundle": "^2.3",
          "incenteev/composer-parameter-handler": "^2.0",
          "jms/serializer-bundle": "^2.4",
          "nelmio/cors-bundle": "^1.5",
          "sensio/distribution-bundle": "^5.0.19",
          "sensio/framework-extra-bundle": "^5.0.0",
          "symfony/monolog-bundle": "^3.1.0",
          "symfony/polyfill-apcu": "^1.0",
          "symfony/swiftmailer-bundle": "^2.6.4",
          "symfony/symfony": "3.4.*",
          "twig/twig": "^1.0||^2.0",
          "symfony/orm-pack": "^1.0"
      },
      "require-dev": {
          "sensio/generator-bundle": "^3.0",
          "symfony/phpunit-bridge": "^4.1"
      },
      "scripts": {
          "symfony-scripts": [
              "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
              "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
              "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
              "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
              "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
              "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
          ],
          "post-install-cmd": [
              "@symfony-scripts"
          ],
          "post-update-cmd": [
              "@symfony-scripts"
          ]
      },
      "extra": {
          "symfony-app-dir": "app",
          "symfony-bin-dir": "bin",
          "symfony-var-dir": "var",
          "symfony-web-dir": "web",
          "symfony-tests-dir": "tests",
          "symfony-assets-install": "relative",
          "incenteev-parameters": {
              "file": "app/config/parameters.yml"
          },
          "branch-alias": {
              "dev-master": "3.4-dev"
          }
      }
  </code></pre>
  
  <p>Product Entity class is:</p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Product
   *
   * @ORM\Table(name="Product")
   * @ORM\Entity
   */
  class Product
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="idProduct", type="integer", nullable=false)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      private $idproduct;
  
      /**
       * @var string
       *
       * @ORM\Column(name="productName", type="string", length=100, nullable=false)
       */
      private $productname;
  
      /**
       * @var boolean
       *
       * @ORM\Column(name="Purchased", type="boolean", nullable=true)
       */
      private $purchased;
  
      /**
       * @var \Doctrine\Common\Collections\Collection
       *
       * @ORM\ManyToMany(targetEntity="User", mappedBy="productproduct")
       */
      private $useruser;
  
      /**
       * Constructor
       */
      public function __construct()
      {
          $this-&gt;useruser = new \Doctrine\Common\Collections\ArrayCollection();
      }
  
  }
  </code></pre>
  
  <p>and then, ProductRepository file is:</p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Repository;
  
  use Doctrine\ORM\EntityRepository;
  
  class ProductRepository extends EntityRepository
  {
      public function getAllProduct()
      {
          $conn = $this-&gt;getEntityManager()-&gt;getConnection();
          $sql = "SELECT * from product";
          $stmt = $conn-&gt;prepare($sql);
          $stmt-&gt;execute();
          return $stmt-&gt;fetchAll();
      }
  }
  </code></pre>
  
  <p>I've also tried to replace </p>
  
  <pre><code>    $restresult = $em-&gt;getRepository('AppBundle:Product')-&gt;getAllProduct();
  </code></pre>
  
  <p>with </p>
  
  <pre><code>    $restresult = $em-&gt;getRepository(Product::class)-&gt;getAllProduct();
  </code></pre>
  
  <p>but the error now is: 
  -"Class 'App\Entity\Product' does not exist"
  -"Doctrine\Common\Persistence\Mapping\MappingException"</p>
  
  <p>I've already tried the solutions of other stack overlow's users about this topic but nothing.
  Someone can help me please?</p>