title: How to use setter dependency injection on entity
body: <p>I wish to use setter injection on my article entity, but I'm new to this and don't understand it too well.</p>
  
  <p>My error is:</p>
  
  <pre><code>My\NewsBundle\Entity\Article
  Fatal error: Call to a member function addArticle() on a non-object 
  </code></pre>
  
  <p>This happens here in my article entity:</p>
  
  <pre><code>/** Inject service: search */
  protected $search;
  public function setSearch(Search $search)
  {
      $this-&gt;search = $search;
  }
  
  /** @ORM\PostPersist */
  public function postPersist()
  {
      // wrong: does not have id yet for prePersist; changed to postPersist
      //$search = new \My\NewsBundle\Entity\Search();
      echo get_class($this-&gt;search);
      $this-&gt;search-&gt;addArticle($this);
  }
  </code></pre>
  
  <p>FYI: my config.yml has:</p>
  
  <pre><code># Parameters
  parameters:
    search.class:  My\NewsBundle\Entity\Search
    google.class:  My\NewsBundle\Entity\Google
    flickr.class:  My\NewsBundle\Entity\Flickr
    article.class: My\NewsBundle\Entity\Article
  
  # Servers
  services:
    search:
      class:       %search.class%
    google:
      class:       %google.class%
    flickr:
      class:       %flickr.class%
    article:
      class:       %article.class%
      calls:
        -          [setSearch, [@search]]
  </code></pre>
  
  <p>FYI: I'm running a ContainerAwareCommand and that consumes a feed; extract from Feed entity:</p>
  
  <pre><code>        $article = $em-&gt;getRepository('MyNewsBundle:Article')-&gt;findOneBy(array('feed'=&gt;$this-&gt;getId(), 'link'=&gt;$item-&gt;link()));
          if (!$article) {
              $article = new \My\NewsBundle\Entity\Article();
  </code></pre>
  
  <p>Any advice on how setter injection works or how to get that service in my entity would be greatly appreciated.</p>