title: Use ChoiceList for entity type
body: <p>I'm trying to use a choice list in a form with the entity type but it's not working if I add data to the form. It's giving me a "could not convert object to int" error.</p>
  
  <p><strong>My buildForm method</strong></p>
  
  <pre><code>public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder-&gt;add('department', 'entity', array(
              'label' =&gt; 'Form.department',
              'class' =&gt; 'HotfloSystemCoreBundle:Department',
              'choice_list' =&gt; $this-&gt;departmentChoiceList,
              'multiple' =&gt; true,
              'required' =&gt; false,
              'attr' =&gt; array(
                  'class' =&gt; 'selectpicker',
                  'data-actions-box' =&gt; true,
                  'data-live-search' =&gt; true,
                  'data-selected-text-format' =&gt; 'count'
              ),
              'horizontal' =&gt; false,
          ));
  }
  </code></pre>
  
  <p><strong>My ChoiceList</strong></p>
  
  <pre><code>class DepartmentChoiceList extends LazyChoiceList
  {
      /**
       * @var EntityManager
       */
      protected $em;
  
      public function __construct($em)
      {
          $this-&gt;em = $em;
      }
  
      /**
       * Loads the choice list
       * Should be implemented by child classes.
       *
       * @return ChoiceListInterface The loaded choice list
       */
      protected function loadChoiceList()
      {
          $departments = $this-&gt;getDepartments();
          $departmentChoices = [];
          foreach ($departments as $department) {
              $departmentChoices[$department-&gt;getId()] = $department;
          }
          // Return the choice list
          return new SimpleChoiceList($departmentChoices);
      }
  
      /**
       * Get the departments available in the poli appointment data
       *
       * @return Department[]
       */
      protected function getDepartments()
      {
          // Get the used department out of the appointment table by using a group by SQL statement
          /** @var $qb QueryBuilder */
          $qb = $this-&gt;em-&gt;getRepository('MyBundle:PoliAnalyzeAppointment')
              -&gt;createQueryBuilder('appointment');
          $qb-&gt;select('DISTINCT IDENTITY(appointment.department)');
  
          // Get the actual departments
          /** @var $qb2 QueryBuilder */
          $qb2 = $this-&gt;em-&gt;getRepository('MyBundle:Department')
              -&gt;createQueryBuilder('department');
          $qb2-&gt;where($qb2-&gt;expr()-&gt;in('department.id', $qb-&gt;getDQL()));
          $qb2-&gt;orderBy('department.name', 'ASC');
  
          return $qb2-&gt;getQuery()-&gt;getResult();
      }
  }
  </code></pre>
  
  <p>I'm using the entity type because it should be converted to an entity and back. If I use the choice type I have to do this myself (which I don't want).</p>
  
  <p>How can I achieve this?</p>