title: Doctrine 2: disable lazy loading / proxy generation.
body: <p>Using Doctrine 2, is it possible to either:</p>
  
  <ul>
  <li>Exclude a property from the generated proxy class?</li>
  <li>Disable lazy loading / proxy generation altogether?</li>
  </ul>
  
  <p>I'm having problems serializing my entities (using Symfony and JMS Serializer). I want to only serialize the associated entities that I explicitly fetch in my query. </p>
  
  <p>The solution described in f.e. <a href="https://stackoverflow.com/questions/11575345/disable-doctrine-2-lazy-loading-when-using-jms-serializer">Disable Doctrine 2 lazy loading when using JMS Serializer?</a> is only partially working. When you have a virtual property:</p>
  
  <pre><code>use Doctrine\ORM\Mapping as ORM;
  use JMS\Serializer\Annotation as Serializer;
  
  /**
   * Profile
   *
   * @ORM\Table(name="profile")
   * @ORM\Entity
   */
  class Profile
  {
      // ...
  
      /**
       * @return string
       *
       * @Serializer\VirtualProperty()
       */
      public function getLabel()
      {
          return implode(' ', [$this-&gt;firstname, $this-&gt;lastname]) . " ({$this-&gt;email})";
      }
  }
  </code></pre>
  
  <p>the associated class is still loaded through the proxy in the serialization process.</p>