title: Doctrine createNativeQuery returns no results
body: <h2>tl;dr</h2>
  
  <p>I have a working SQL query which returns rows from the SQL commandline, but not when submitted through Doctrine. I think the problem is in how I'm setting the <code>ResultSetMapper</code>.  I've read the <a href="http://doctrine-orm.readthedocs.org/en/latest/reference/native-sql.html" rel="noreferrer">docs</a> about native queries but I must be missing something. What is it?</p>
  
  <h2>Details</h2>
  
  <h2>query</h2>
  
  <p>The following query run from the SQL commandline produces 1 row:</p>
  
  <pre><code>SELECT t.*
  FROM 
    StateLogItem s NATURAL JOIN (
      SELECT 
        task_id, 
        MAX(
          COALESCE(updatedAt, createdAt)
        ) d, 
        MAX(id) id 
      FROM 
        StateLogItem 
      WHERE 
        dtype = 'transitionlogitem' 
      GROUP BY 
        task_id
    ) m 
    RIGHT JOIN Task t ON t.id = s.task_id 
  WHERE  s.toState = 'started';
  </code></pre>
  
  <h2>results:</h2>
  
  <pre><code>'20', 1, NULL, 'just because', '2014-07-18 10:49:00', NULL
  </code></pre>
  
  <h2>using <code>ResultSetMapping</code></h2>
  
  <p>When I attempt to run the same query via Doctrine in a Symfony EntityRepository (as follows), I get zero rows even though the Symfony profiler indicates that the correct query was successfully run.</p>
  
  <pre><code>public function findByActionStatus($status){
      $sql = "SELECT t.id, t.description, t.created_by, t.updated_by, t.createdAt, t.updatedAt
              FROM StateLogItem s
                  NATURAL JOIN (
                      SELECT task_id, MAX(COALESCE(updatedAt,createdAt)) d, MAX(id) id
                      FROM StateLogItem
                      WHERE dtype = 'transitionlogitem'
                      GROUP BY task_id
                  ) m
                  RIGHT JOIN Task t ON t.id=s.task_id
              WHERE s.toState = :status";
  
      $em = $this-&gt;getEntityManager();
  
      $rsm = new ResultSetMapping();
      $rsm-&gt;addEntityResult('ACCQueueBundle:Task', 't');
      $rsm-&gt;addFieldResult('t','t.id','id');
      $rsm-&gt;addFieldResult('t','t.created_by','createdBy');
      $rsm-&gt;addFieldResult('t','t.updated_by','updatedBy');
      $rsm-&gt;addFieldResult('t','t.description','description');
      $rsm-&gt;addFieldResult('t','t.createdAt','createdAt');
      $rsm-&gt;addFieldResult('t','t.updatedAt','updatedAt');
  
      $rsm-&gt;addJoinedEntityResult('ACCQueueBundle:TransitionLogItem','s','t','transitions'); //tried with and without
  
  
      $query = $em-&gt;createNativeQuery($sql,$rsm);
      $query-&gt;setParameter('status', $status);
  
      return $query-&gt;getResult();
  
  }
  </code></pre>
  
  <h2>entity</h2>
  
  <p>The <code>Task</code> entity looks like this:</p>
  
  <pre><code>namespace ACC\QueueBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  
  use Symfony\Component\Validator\Constraints as Assert;
  use Doctrine\Common\Collections\ArrayCollection;
  use ACC\Traits\BlameableTrait;
  use ACC\MainBundle\Entity\Traits\HasDocumentsTrait;
  use Gedmo\Mapping\Annotation as Gedmo;
  use Gedmo\Timestampable\Traits\TimestampableEntity;    
  
  
  /**
   * Task
   * @ORM\Entity(repositoryClass="ACC\QueueBundle\Entity\TaskRepository")
   * @ORM\HasLifecycleCallbacks()
   *
   */
  class Task {
  
      use HasDocumentsTrait;
      use BlameableTrait;
      use TimestampableEntity;
  
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
  
      /**
       * @var Transition
       *
       * @ORM\OneToMany(targetEntity = "TransitionLogItem", mappedBy = "task", orphanRemoval = true, cascade = {"persist"})
       * @ORM\OrderBy({"createdAt" = "ASC"})
       */
      protected $transitions;
  
      /**
       * @var Pause
       *
       * @ORM\OneToMany(targetEntity = "PauseLogItem", mappedBy = "task", orphanRemoval = true, cascade = {"persist"})
       * @ORM\OrderBy({"createdAt" = "ASC"})
       */
      protected $pauses;
  
  
      /**
       * @var string
       *
       * @ORM\Column(name="description", type="text")
       */
      protected $description;
  
      /**
       * @ORM\ManyToMany(targetEntity = "ACC\MainBundle\Entity\Document", cascade={"persist","remove"})
       * @ORM\JoinTable(name="Task_Document",
       *  joinColumns={@ORM\JoinColumn(name="task_id", referencedColumnName="id")},
       *  inverseJoinColumns={@ORM\JoinColumn(name="document_id", referencedColumnName="id", unique=true)})
       */
      protected $documents;
  
  //etc.
  </code></pre>
  
  <h2>specs:</h2>
  
  <ul>
  <li>PHP 5.5.14</li>
  <li>Doctrine ORM 2.4.4</li>
  <li>Symfony 2.5.2</li>
  <li>symfony environment: dev</li>
  <li>5.5.34-MariaDB-log</li>
  </ul>