title: symfony2 Catchable Fatal Error: Object of class could not be converted to string
body: <p>I have this Entity defined:</p>
  
  <pre><code>&lt;?php
  
  namespace Apw\BlackbullBundle\Entity;
  
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
  * Categories
  *
  * @ORM\Table()
  *    @ORM\Entity(repositoryClass="Apw\BlackbullBundle\Entity\CategoriesRepository")
  */
  class Categories
  {
  /**
   * @var integer
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @var string
   *
   * @ORM\Column(name="categories_image", type="string", length=64, nullable = true)
   */
  private $categoriesImage;
  
  /**
   * @var integer
   *
   * @ORM\Column(name="parent_id", type="integer", nullable = true, options={"default":0})
   */
  private $parentId;
  
  /**
   * @var integer
   *
   * @ORM\Column(name="sort_order", type="integer", nullable = true, options={"default":0})
   */
  private $sortOrder;
  
  /**
   * @var \DateTime
   *
   * @ORM\Column(name="date_added", type="datetime", nullable = true)
   */
  private $dateAdded;
  
  /**
   * @var \DateTime
   *
   * @ORM\Column(name="last_modified", type="datetime", nullable = true)
   */
  private $lastModified;
  
  /**
   * @var boolean
   *
   * @ORM\Column(name="categories_status", type="boolean", nullable = true, options={"default" = 1})
   */
  private $categoriesStatus;
  
  /**
   * @ORM\OneToMany(targetEntity="CategoriesDescription", mappedBy="category", cascade={"persist", "remove"})
   */
  private $categoryDescription;
  
  /**
   * @ORM\ManyToMany(targetEntity="Products", mappedBy="categories")
   **/
  private $products;
  
  /**
   * Get id
   *
   * @return integer
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  
  /**
   * Set categoriesImage
   *
   * @param string $categoriesImage
   * @return Categories
   */
  public function setCategoriesImage($categoriesImage)
  {
      $this-&gt;categoriesImage = $categoriesImage;
  
      return $this;
  }
  
  /**
   * Get categoriesImage
   *
   * @return string
   */
  public function getCategoriesImage()
  {
      return $this-&gt;categoriesImage;
  }
  
  /**
   * Set parentId
   *
   * @param integer $parentId
   * @return Categories
   */
  public function setParentId($parentId)
  {
      $this-&gt;parentId = $parentId;
  
      return $this;
  }
  
  /**
   * Get parentId
   *
   * @return integer
   */
  public function getParentId()
  {
      return $this-&gt;parentId;
  }
  
  /**
   * Set sortOrder
   *
   * @param string $sortOrder
   * @return Categories
   */
  public function setSortOrder($sortOrder)
  {
      $this-&gt;sortOrder = $sortOrder;
  
      return $this;
  }
  
  /**
   * Get sortOrder
   *
   * @return string
   */
  public function getSortOrder()
  {
      return $this-&gt;sortOrder;
  }
  
  /**
   * Set dateAdded
   *
   * @param \DateTime $dateAdded
   * @return Categories
   */
  public function setDateAdded($dateAdded)
  {
      $this-&gt;dateAdded = $dateAdded;
  
      return $this;
  }
  
  /**
   * Get dateAdded
   *
   * @return \DateTime
   */
  public function getDateAdded()
  {
      return $this-&gt;dateAdded;
  }
  
  /**
   * Set lastModified
   *
   * @param \DateTime $lastModified
   * @return Categories
   */
  public function setLastModified($lastModified)
  {
      $this-&gt;lastModified = $lastModified;
  
      return $this;
  }
  
  /**
   * Get lastModified
   *
   * @return \DateTime
   */
  public function getLastModified()
  {
      return $this-&gt;lastModified;
  }
  
  /**
   * Constructor
   */
  public function __construct()
  {
      $this-&gt;categoryDescription = new ArrayCollection();
      $this-&gt;products = new ArrayCollection();
  }
  
  /**
   * Add categoryDescription
   *
   * @param \Apw\BlackbullBundle\Entity\CategoriesDescription $categoryDescription
   * @return Categories
   */
  public function addCategoryDescription(\Apw\BlackbullBundle\Entity\CategoriesDescription $categoryDescription)
  {
      $this-&gt;categoryDescription[] = $categoryDescription;
  
      return $this;
  }
  
  /**
   * Remove categoryDescription
   *
   * @param \Apw\BlackbullBundle\Entity\CategoriesDescription $categoryDescription
   */
  public function removeCategoryDescription(\Apw\BlackbullBundle\Entity\CategoriesDescription $categoryDescription)
  {
      $this-&gt;categoryDescription-&gt;removeElement($categoryDescription);
  }
  
  /**
   * Get categoryDescription
   *
   * @return \Doctrine\Common\Collections\Collection
   */
  public function getCategoryDescription()
  {
      return $this-&gt;categoryDescription;
  }
  
  /**
   * Add products
   *
   * @param \Apw\BlackbullBundle\Entity\Products $products
   * @return Categories
   */
  public function addProduct(\Apw\BlackbullBundle\Entity\Products $products)
  {
      $this-&gt;products[] = $products;
  
      return $this;
  }
  
  /**
   * Remove products
   *
   * @param \Apw\BlackbullBundle\Entity\Products $products
   */
  public function removeProduct(\Apw\BlackbullBundle\Entity\Products $products)
  {
      $this-&gt;products-&gt;removeElement($products);
  }
  
  /**
   * Get products
   *
   * @return \Doctrine\Common\Collections\Collection
   */
  public function getProducts()
  {
      return $this-&gt;products;
  }
  
  /**
   * Set categoriesStatus
   *
   * @param boolean $categoriesStatus
   * @return Categories
   */
  public function setCategoriesStatus($categoriesStatus)
  {
      $this-&gt;categoriesStatus = $categoriesStatus;
  
      return $this;
  }
  
  /**
   * Get categoriesStatus
   *
   * @return boolean
   */
  public function getCategoriesStatus()
  {
      return $this-&gt;categoriesStatus;
  }
  }
  </code></pre>
  
  <p>Then I have this method in my controller for handle form submission:</p>
  
  <pre><code>&lt;?php
  
  namespace Apw\BlackbullBundle\Controller;
  
  
  use Apw\BlackbullBundle\Entity\Categories;
  use Apw\BlackbullBundle\Entity\CategoriesDescription;
  use Apw\BlackbullBundle\Form\CategoriesType;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  use Symfony\Component\HttpFoundation\JsonResponse;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  
  
  class CategoriesController extends Controller
  {
     /**
   * @Security("has_role('ROLE_ADMIN')")
   * @Route("/createCategory")
   * @Template()
   */
  
  public function createCategoryAction(Request $request){
  
      $category = new Categories();
      $categoryDesc = new CategoriesDescription();
      $category-&gt;addCategoryDescription($categoryDesc);
      $categoryDesc-&gt;setCategory($category);
  
      $form = $this-&gt;createForm(new CategoriesType(), $category);
      $form-&gt;handleRequest($request);
  
      if($form-&gt;isValid()){
          //exit(\Doctrine\Common\Util\Debug::dump($category));
          $em = $this-&gt;getDoctrine()-&gt;getManager();
  
          $em-&gt;persist($category);
          $em-&gt;persist($categoryDesc);
          $em-&gt;flush();
  
          return $this-&gt;redirect($this-&gt;generateUrl('apw_blackbull_categories_showcategories'));
      }
  
      return array(
          'form' =&gt; $form-&gt;createView()
      );
  }
  
  }
  </code></pre>
  
  <p>And finally this is my CategoryType.php:</p>
  
  <pre><code>&lt;?php
  
  namespace Apw\BlackbullBundle\Form;
  
  use Doctrine\ORM\EntityRepository;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  
  class CategoriesType extends AbstractType
  {
      /**
       * @param FormBuilderInterface $builder
       * @param array $options
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('categoryDescription', 'collection',
                  array(
                      'type' =&gt; new CategoriesDescriptionType(),
                      'allow_add' =&gt; true,
                      'options' =&gt; array('data_class' =&gt; 'Apw\BlackbullBundle\Entity\CategoriesDescription'),
                      'by_reference' =&gt; false,
                  ))
              -&gt;add('categoriesImage', null, array('label'=&gt;'Foto:'))
              -&gt;add('categoriesStatus', null, array('label'=&gt;'Stato:'))
              -&gt;add('parentId', 'entity', array( //provare a mettere una querybuiler
                                              'class'       =&gt; 'ApwBlackbullBundle:CategoriesDescription',
                                              'property'    =&gt; 'categoriesName',
                                              'empty_value' =&gt; 'Scegliere una categoria',
                                              'required'    =&gt; false,
                                              'label'       =&gt; 'Crea in:'))
              -&gt;add('salva','submit')
              -&gt;add('azzera','reset')
          ;
      }
  
      /**
       * @param OptionsResolverInterface $resolver
       */
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'Apw\BlackbullBundle\Entity\Categories',
          ));
      }
  
      /**
       * @return string
       */
      public function getName()
      {
          return 'categories';
      }
  }
  </code></pre>
  
  <p>When I try to save data I get this error:</p>
  
  <blockquote>
    <p>An exception occurred while executing 'INSERT INTO Categories
    (categories_image, parent_id, sort_order, date_added, last_modified,
    categories_status) VALUES (?, ?, ?, ?, ?, ?)' with params ["as", {},
    null, null, null, 1]:</p>
    
    <p>Catchable Fatal Error: Object of class
    Apw\BlackbullBundle\Entity\CategoriesDescription could not be
    converted to string</p>
  </blockquote>
  
  <p>What I'm doing wrong? </p>