title: Symfony 2 - Error : "Call to a member function * on a non-object in * line *
body: <p>I recently learnt Symfony 2, so i'm still a beginner.
  For fun, i'm trying to make a simple social network website.</p>
  
  <p>So I have posts, and hashtags. I create a relation ManyToMany between this two entities (posts/hashtags)</p>
  
  <p>I tried to get a hashtag from my database, by using getRepository.
  I used the method "findByHashtagName". 
  When i got the object, i tried to get the id of the hashtag, but when I called the method getId(), I have this warning :</p>
  
  <pre><code>Call to a member function * on a non-object in * line *
  </code></pre>
  
  <p>When I get the object, I check if it's not null. 
  So I really don't understand why it doesn't work.</p>
  
  <p>Hashtag entity :</p>
  
  <pre><code>&lt;?php
  
  namespace Moodress\Bundle\HashtagBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
  * Hashtag
  *
  * @ORM\Table()
  * @ORM\Entity(repositoryClass="Moodress\Bundle\HashtagBundle\Entity\HashtagRepository")
  */
  class Hashtag
  {
     /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
     private $id;
  
     /**
     * @var string
     *
     * @ORM\Column(name="hashtag_name", type="string", length=255)
     */
     private $hashtagName;
  
  /**
     * @ORM\ManyToMany(targetEntity="Moodress\Bundle\PosteBundle\Entity\Poste", cascade={"persist"})
     */
      private $postes;
  
  
  public function __construct()  
   {
        $this-&gt;postes = new \Doctrine\Common\Collections\ArrayCollection();
   }
  
     /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
      return $this-&gt;id;
    }
  
    /**
     * Set hashtagName
     *
     * @param string $hashtagName
     * @return Hashtag
     */
     public function setHashtagName($hashtagName)
    {
       $this-&gt;hashtagName = $hashtagName;
  
      return $this;
    }
  
    /**
     * Get hashtagName
     *
     * @return string 
     */
  public function getHashtagName()
  {
      return $this-&gt;hashtagName;
  }
  
  /**
   * Add postes
   *
   * @param \Moodress\Bundle\PosteBundle\Entity\Poste $postes
   * @return Hashtag
   */
  public function addPoste(\Moodress\Bundle\PosteBundle\Entity\Poste $postes)
  {
      $this-&gt;postes[] = $postes;
  
      return $this;
  }
  
  /**
   * Remove postes
   *
   * @param \Moodress\Bundle\PosteBundle\Entity\Poste $postes
   */
  public function removePoste(\Moodress\Bundle\PosteBundle\Entity\Poste $postes)
  {
      $this-&gt;postes-&gt;removeElement($postes);
  }
  
  /**
   * Get postes
   *
   * @return \Doctrine\Common\Collections\Collection 
   */
   public function getPostes()
   {
      return $this-&gt;postes;
   }
  }
  </code></pre>
  
  <p>Post file :</p>
  
  <pre><code>&lt;?php
  
  namespace Moodress\Bundle\PosteBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
  * Poste
  *
  * @ORM\Table()
  * @ORM\Entity(repositoryClass="Moodress\Bundle\PosteBundle\Entity\PosteRepository")
  */
  class Poste
  {
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
     private $id;
  
    /**
     * @var integer
     *
     * @ORM\Column(name="id_user", type="integer")
     */
     private $idUser;
  
    /**
     * @var string
     *
     * @ORM\Column(name="description", type="text")
     */
    private $description;
  
    /**
    * @var integer
    *
    * @ORM\Column(name="nb_comments", type="integer")
    */
    private $nbComments;
  
    /**
    * @var integer
    *
    * @ORM\Column(name="nb_likes", type="integer")
    */
    private $nbLikes;
  
    /**
     * @var \DateTime
     *
     * @ORM\Column(name="date_creation", type="datetime")
     */
  private $dateCreation;
  
   /**
    * @var boolean
    *
    * @ORM\Column(name="is_there_fashtag", type="boolean")
    */
   private $isThereFashtag;
  
  
  /**
   * @var array
   *
   * @ORM\Column(name="array_url_pictures", type="array")
   */
  private $arrayUrlPicturesMaxSize;
  
  /**
   * Constructor
   */
  public function __construct()
  {
      $this-&gt;dateCreation = new \Datetime();
      $this-&gt;arrayUrlPicturesMaxSize = array();
      $this-&gt;nbComments = 0;
      $this-&gt;nbLikes = 0;
      $this-&gt;isThereFashtag = false;
  }
  
  /**
   * Get id
   *
   * @return integer 
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  
  /**
   * Set idUser
   *
   * @param integer $idUser
   * @return Poste
   */
  public function setIdUser($idUser)
  {
      $this-&gt;idUser = $idUser;
  
      return $this;
  }
  
  /**
   * Get idUser
   *
   * @return integer 
   */
  public function getIdUser()
  {
      return $this-&gt;idUser;
  }
  
  /**
   * Set description
   *
   * @param string $description
   * @return Poste
   */
  public function setDescription($description)
  {
      $this-&gt;description = $description;
  
      return $this;
  }
  
  /**
   * Get description
   *
   * @return string 
   */
  public function getDescription()
  {
      return $this-&gt;description;
  }
  
  /**
   * Set nbComments
   *
   * @param integer $nbComments
   * @return Poste
   */
  public function setNbComments($nbComments)
  {
      $this-&gt;nbComments = $nbComments;
  
      return $this;
  }
  
  /**
   * Get nbComments
   *
   * @return integer 
   */
  public function getNbComments()
  {
      return $this-&gt;nbComments;
  }
  
  /**
   * Set nbLikes
   *
   * @param integer $nbLikes
   * @return Poste
   */
  public function setNbLikes($nbLikes)
  {
      $this-&gt;nbLikes = $nbLikes;
  
      return $this;
  }
  
  /**
   * Get nbLikes
   *
   * @return integer 
   */
  public function getNbLikes()
  {
      return $this-&gt;nbLikes;
  }
  
  /**
   * Set dateCreation
   *
   * @param \DateTime $dateCreation
   * @return Poste
   */
  public function setDateCreation($dateCreation)
  {
      $this-&gt;dateCreation = $dateCreation;
  
      return $this;
  }
  
  /**
   * Get dateCreation
   *
   * @return \DateTime 
   */
  public function getDateCreation()
  {
      return $this-&gt;dateCreation;
  }
  
  /**
   * Set isThereFashtag
   *
   * @param boolean $isThereFashtag
   * @return Post
   */
  public function setIsThereFashtag($isThereFashtag)
  {
      $this-&gt;isThereFashtag = $isThereFashtag;
  
      return $this;
  }
  
  /**
   * Get isThereFashtag
   *
   * @return boolean 
   */
  public function getIsThereFashtag()
  {
      return $this-&gt;isThereFashtag;
  }
  
  public function addPicture($picture, $posteId)
  {
      $directory = "/Applications/MAMP/htdocs/moodress-website/Symfony/web/images/postes_images";
      $picture-&gt;move($directory, "post_".$posteId."_pic_".count($this-&gt;arrayUrlPicturesMaxSize).".".$picture-&gt;getClientOriginalExtension());
      $this-&gt;arrayUrlPicturesMaxSize[] = "images/postes_images/poste_".$posteId."_pic_".count($this-&gt;arrayUrlPicturesMaxSize).".".$picture-&gt;getClientOriginalExtension();
  }
  
  /**
   * Set arrayUrlPicturesMaxSize
   *
   * @param array $arrayUrlPicturesMaxSize
   * @return Poste
   */
  public function setArrayUrlPicturesMaxSize($arrayUrlPicturesMaxSize)
  {
      $this-&gt;arrayUrlPicturesMaxSize = $arrayUrlPicturesMaxSize;
  
      return $this;
  }
  
  /**
   * Get arrayUrlPicturesMaxSize
   *
   * @return array 
   */
  public function getArrayUrlPicturesMaxSize()
  {
      return $this-&gt;arrayUrlPicturesMaxSize;
   }
  }
  </code></pre>
  
  <p>The code failing :</p>
  
  <pre><code>   $em = $this-&gt;getDoctrine()-&gt;getManager();
     $hashtag1 = $em-&gt;getRepository('MoodressHashtagBundle:Hashtag')-&gt;findByHashtagName("bcbg");
  
       if (!$hashtag1) {
              throw $this-&gt;createNotFoundException(
          'None hashtag found');
      }
      else {
          $hashtag1-&gt;getHashtagName();
              // This call make the exception : Call to a member function * on a non-object in * line *
  }
  </code></pre>
  
  <p>What do I do wrong ?</p>
  
  <p>I check if it's null... It's not, because I try to call getHashtagName... As you see, this methode is in Hashtag entity.</p>