title: Doctrine2 "Class does not exist" error when calling an entity repository
body: <p>I have some problems with the annotations system of doctrine 2 (I use the 2.3 that I integrated into Zend framework 2). On relatively simple relation I have no problems, but there I have many tables in cascade and when I call the repository find method, I get a Class does not exist error here : </p>
  
  <pre><code>doctrine\orm\lib\Doctrine\ORM\Proxy\ProxyFactory.php:233
  </code></pre>
  
  <p>There's probably some problems with the database schema itself, but I can't change it, I have to make my app from this database.</p>
  
  <p>All my entities starts by :</p>
  
  <pre><code>namespace Gcl\Entities;
  use Doctrine\ORM\Mapping as ORM;
  </code></pre>
  
  <p>Here's some of my entities :</p>
  
  <p>TCompanyGcl</p>
  
  <pre><code>    /**
       * TCompanyGcl
       *
       * @ORM\Table(name="T_COMPANY_GCL")
       * @ORM\Entity(repositoryClass="Gcl\Repositories\TCompanyGclRepository")
       */
      class TCompanyGcl
      {
             /**
               * @var ArrayCollection $customerAccounts
               *
               * @ORM\OneToMany(targetEntity="TCustomerAccount", mappedBy="tCompanyGcl")
               */
              private $customerAccounts;
  </code></pre>
  
  <p>TCustomerAccount</p>
  
  <pre><code>/**
   * TCustomerAccount
   *
   * @ORM\Table(name="T_CUSTOMER_ACCOUNT")
   * @ORM\Entity
   */
  class TCustomerAccount
  {
     /**
       * @var \TCompanyGcl
       *
       * @ORM\ManyToOne(targetEntity="TCompanyGcl", cascade={"all"}, fetch="EAGER")
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name="COMPANY_ID", referencedColumnName="COMPANY_ID")
       * })
       */
      private $tCompanyGcl;
  
      /**
       * @var \TPerson
       *
       * @ORM\ManyToOne(targetEntity="TPerson", cascade={"all"}, fetch="EAGER")
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name="PERSON_ID", referencedColumnName="PERSON_ID")
       * })
       */
      private $person;
  
      /**
       * @var ArrayCollection $customerSubscriptions
       *
       * @ORM\OneToMany(targetEntity="TSubscription", mappedBy="customerAccount")
       */
      private $customerSubscriptions;
  </code></pre>
  
  <p>TSubscriptions</p>
  
  <pre><code>/**
   * TSubscription
   *
   * @ORM\Table(name="T_SUBSCRIPTION")
   * @ORM\Entity(repositoryClass="Gcl\Repositories\TSubscriptionRepository")
   */
  class TSubscription
  {
     /**
       * @var \TCustomerAccount
       *
       * @ORM\ManyToOne(targetEntity="TCustomerAccount", inversedBy="customerSubscriptions")
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name="CUSTOMER_ACCOUNT_ID", referencedColumnName="CUSTOMER_ACCOUNT_ID")
       * })
       */
      private $customerAccount;
  </code></pre>
  
  <p>So the problem is that when I do things like :</p>
  
  <pre><code>$account = $em-&gt;getRepository('Gcl\Entities\TCustomerAccount')-&gt;find(1);
  $account-&gt;getSubscriptions();
  $account-&gt;getCompanyGcl();
  </code></pre>
  
  <p>It works, or when I go all the way down to subscriptions from TCompanyGcl it also works.
  But when I do :</p>
  
  <pre><code>$subscription = $em-&gt;getRepository('Gcl\Entities\TSubscription')-&gt;find(1);
  </code></pre>
  
  <p>I get the error described above.</p>
  
  <p>If somebody have the slightest lead on the problem I would greatly appreciate the help.</p>
  
  <p><strong>EDIT :</strong>
  Here's the repositories :
  TCompanyGclRepositories</p>
  
  <pre><code>namespace Gcl\Repositories;
  
  use Doctrine\ORM\EntityRepository;
  
  class TCompanyGclRepository extends EntityRepository
  {
      /**
       * Récupère la liste des sociétés dont le champ passé en paramètre contient la chaîne de caractères passée en paramètre
       *
       * @param string field nom du champ dans lequel chercher
       * @param string search chaîne de recherche
       * @return Array company
       */
      public function getCompaniesByField($field = 'companyName', $search = '', $return_mode = 'array'){
          $qb = $this-&gt;_em-&gt;createQueryBuilder();
          $qb-&gt;select('c')
          -&gt;from('Gcl\Entities\TCompanyGcl',  'c')
          -&gt;where('UPPER(c.'.$field.') LIKE :search')
          -&gt;setParameter('search', "%".mb_strtoupper($search,'UTF-8')."%");
  
          if($return_mode=="array"){
              $results = $qb-&gt;getQuery()-&gt;getArrayResult();
              $companies = array(0 =&gt; "Pas de société");
  
              foreach($results as $result){
                  $companies[$result['companyId']] = $result;
              }
          }
          else{
              $companies = $qb-&gt;getQuery()-&gt;getResult();
          }
  
          return $companies;
      }
  
      public function getCustomerAccountPerson($companyId){
          $qb = $this-&gt;_em-&gt;createQueryBuilder();
          $qb-&gt;select('cust, p, t')
                      -&gt;from('Gcl\Entities\TCustomerAccount', 'cust')
                      -&gt;leftJoin('cust.person', 'p')
                      -&gt;leftJoin('p.typeofcivility', 't')
                      -&gt;where('cust.companyId = :id')
                      -&gt;setParameter('id', $companyId);
          return $qb-&gt;getQuery()-&gt;getResult();
  
      }
  }
  </code></pre>
  
  <p>TSubscriptionRepositories</p>
  
  <pre><code>namespace Gcl\Repositories;
  
  use Doctrine\ORM\EntityRepository;
  
  class TSubscriptionRepository extends EntityRepository
  {
      public function getContractTickets($subscription_id){
          $qb = $this-&gt;_em-&gt;createQueryBuilder();
  
          if(!is_array($subscription_id)){
              $subscription_id = array($subscription_id);
          }
          $qb-&gt;select('s, t, i, s.itemId, s.subscriptionId, i.printName, t.ticketSerialNumber')
          -&gt;from('Gcl\Entities\TSubscription', 's')
          -&gt;innerJoin('s.ticketSerialNumber', 't')
          -&gt;leftJoin('s.item', 'i')
          -&gt;add('where', $qb-&gt;expr()-&gt;in('s.subscriptionId', $subscription_id));
          return $qb-&gt;getQuery()-&gt;getArrayResult();
      }
  
      public function getContractVehicles($subscription_id){
          $qb = $this-&gt;_em-&gt;createQueryBuilder();
  
          if(!is_array($subscription_id)){
              $subscription_id = array($subscription_id);
          }
          $qb-&gt;select('s, v, tv, s.itemId, i.printName, v.licencePlate, tv.name')
          -&gt;from('Gcl\Entities\TSubscription', 's')
          -&gt;innerJoin('s.licencePlate', 'v')
          -&gt;leftJoin('v.typeOfVehicle', 'tv')
          -&gt;leftJoin('s.item', 'i')
          -&gt;add('where', $qb-&gt;expr()-&gt;in('s.subscriptionId', $subscription_id));
          return $qb-&gt;getQuery()-&gt;getArrayResult();
      }
  }
  </code></pre>
  
  <p>My Entities are in the folder Gcl/Entities and my repositories in Gcl/Repositories. When I remove some associations from the entites I can call them and their methods just fine.
  But if when calling the find method on the Subscription repositories I remove the tCompanyGcl and person associations from TCustomerAccount I get this error :</p>
  
  <pre><code>Class Gcl\Entities\ArrayCollection does not exist
  </code></pre>