title: symfony2 doctrine ResultSetMapping error
body: <p>Here I am try to use ResultSetMapping to map the result which generate by nativeQuery. But I have no idea about why the doctrine always throw Undefined index error. anyone can help me out from this problem?
  Here is my code:
  the PlaceMarkerRepository:</p>
  
  <pre><code>namespace Leo\FoodRadarBundle\Entity;
  
  use Doctrine\ORM\EntityRepository;
  use Doctrine\ORM\Query\ResultSetMappingBuilder;
  
  
  /**
   * PlaceMarkerRepository
   *
   * This class was generated by the Doctrine ORM. Add your own custom
   * repository methods below.
   */
  class PlaceMarkerRepository extends EntityRepository
  {
      public function findNearBy($query,$lat, $lng, $radius){
  
          $rsm = new ResultSetMappingBuilder($this-&gt;getEntityManager());
          // $rsm = new ResultSetMappingBuilder();
          // $rsm-&gt;addRootEntityFromClassMetadata('LeoFoodRadarBundle:PlaceMarker', 'p');
          // $rsm-&gt;addJoinedEntityFromClassMetadata('LeoFoodRadarBundle:Coordinate', 'c', 'p', 'coordinate', array('id' =&gt; 'coordinate_id'));
  
          $rsm-&gt;addEntityResult('LeoFoodRadarBundle:PlaceMarker', 'p');
          $rsm-&gt;addFieldResult('p', 'id', 'id');
          $rsm-&gt;addFieldResult('p', 'name', 'name');
          $rsm-&gt;addJoinedEntityResult('LeoFoodRadarBundle:Coordinate' , 'c', 'p', 'coordinate');
          $rsm-&gt;addFieldResult('c', 'coordinate_id', 'id');
          $rsm-&gt;addFieldResult('c', 'latitude', 'latitude');
          $rsm-&gt;addFieldResult('c', 'longitude', 'longitude');
  
  
  
          $sql ="SELECT p.id, p.name, c.latitude, c.longitude, c.id as coordinate_id
                  FROM placeMarker p join coordinate c on p.coordinate_id = c.id
                  ";
  
           $this-&gt;getEntityManager()-&gt;createNativeQuery($sql, $rsm)-&gt;getResult();
  
  
  
      }
  }
  </code></pre>
  
  <p>and PlaceMark:</p>
  
  <pre><code>namespace Leo\FoodRadarBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Leo\FoodRadarBundle\Entity\PlaceMarker
   *
   * @ORM\Table(name="placeMarker")
   * @ORM\Entity(repositoryClass="Leo\FoodRadarBundle\Entity\PlaceMarkerRepository")
   */
  class PlaceMarker {
  
      /**
       * @var integer $id
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var Coordinate coordinate 
       * @ORM\OneToOne(targetEntity="Coordinate") 
       * @ORM\JoinColumn(name="coordinate_id", referencedColumnName="id")
       */
      private $coordinate;
  
      /**
       *
       * @var Address address
       * @ORM\OneToOne(targetEntity="Address") 
       * @ORM\JoinColumn(name="address_id", referencedColumnName="id")
       */
      private $address;
  
  
      /**
       *
       * @ORM\Column(name="name", type="string", length=100)
       */
      private $name;
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId() {
          return $this-&gt;id;
      }
  
      /**
       * Set coordinate
       *
       * @param Leo\FoodRadarBundle\Entity\Coordinate $coordinate
       * @return PlaceMarker
       */
      public function setCoordinate(\Leo\FoodRadarBundle\Entity\Coordinate $coordinate = null) {
          $this-&gt;coordinate = $coordinate;
  
          return $this;
      }
  
      /**
       * Get coordinate
       *
       * @return Leo\FoodRadarBundle\Entity\Coordinate 
       */
      public function getCoordinate() {
          return $this-&gt;coordinate;
      }
  
      /**
       * Set address
       *
       * @param Leo\FoodRadarBundle\Entity\Address $address
       * @return PlaceMarker
       */
      public function setAddress(\Leo\FoodRadarBundle\Entity\Address $address = null) {
          $this-&gt;address = $address;
  
          return $this;
      }
  
      /**
       * Get address
       *
       * @return Leo\FoodRadarBundle\Entity\Address 
       */
      public function getAddress() {
          return $this-&gt;address;
      }
  
  
  
      /**
       * Set name
       *
       * @param string $name
       * @return PlaceMarker
       */
      public function setName($name)
      {
          $this-&gt;name = $name;
  
          return $this;
      }
  
      /**
       * Get name
       *
       * @return string 
       */
      public function getName()
      {
          return $this-&gt;name;
      }
  }
  </code></pre>
  
  <p>The Coordinate:</p>
  
  <pre><code>&lt;?php
  
  namespace Leo\FoodRadarBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Leo\FoodRadarBundle\Entity\Coordinate
   *
   * @ORM\Table(name="coordinate")
   * @ORM\Entity
   */
  class Coordinate
  {
      /**
       * @var integer $id
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @ORM\Column(type="float") 
       */
      private $longitude;
  
      /**
       * @ORM\Column(type="float") 
       */
      private $latitude;
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
  
      /**
       * Get longitude
       * @return float 
       */
      public function getLongitude() {
          return $this-&gt;longitude;
      }
  
      /**
       * Set longitude
       */
      public function setLongitude($longitude) {
          $this-&gt;longitude = $longitude;
      }
  
      /**
       * Get Latitude
       * @return float 
       */
      public function getLatitude() {
          return $this-&gt;latitude;
      }
  
      /**
       * Set Latitude
       */
      public function setLatitude($latitude) {
          $this-&gt;latitude = $latitude;
      }
  
  
  }
  </code></pre>
  
  <p>the error caused by this statement:</p>
  
  <pre><code>$targetClass = $this-&gt;_ce[$relation['targetEntity']];
  </code></pre>
  
  <p>the information about error is:</p>
  
  <pre><code>Notice: Undefined index: Leo\FoodRadarBundle\Entity\Coordinate in /Volumes/DATA/LEO/Sites/FoodRadar/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php line 427 
  
   ErrorHandler -&gt;handle ('8', 'Undefined index: Leo\FoodRadarBundle\Entity\Coordinate', '/Volumes/DATA/LEO/Sites/FoodRadar/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php', '427', array('row' =&gt; array('id' =&gt; '1', 'name' =&gt; 'test', 'latitude' =&gt; '233.234342', 'longitude' =&gt; '-232.23232323232', 'coordinate_id' =&gt; '2'), 'cache' =&gt; array('id' =&gt; array('fieldName' =&gt; 'id', 'type' =&gt; object(IntegerType), 'isIdentifier' =&gt; true, 'dqlAlias' =&gt; 'p'), 'name' =&gt; array('fieldName' =&gt; 'name', 'type' =&gt; object(StringType), 'isIdentifier' =&gt; false, 'dqlAlias' =&gt; 'p'), 'latitude' =&gt; array('fieldName' =&gt; 'latitude', 'type' =&gt; object(FloatType), 'isIdentifier' =&gt; false, 'dqlAlias' =&gt; 'c'), 'longitude' =&gt; array('fieldName' =&gt; 'longitude', 'type' =&gt; object(FloatType), 'isIdentifier' =&gt; false, 'dqlAlias' =&gt; 'c'), 'coordinate_id' =&gt; array('fieldName' =&gt; 'id', 'type' =&gt; object(IntegerType), 'isIdentifier' =&gt; true, 'dqlAlias' =&gt; 'c')), 'result' =&gt; array(object(PlaceMarker)), 'id' =&gt; array('p' =&gt; '|1', 'c' =&gt; '|2'), 'nonemptyComponents' =&gt; array('p' =&gt; true, 'c' =&gt; true), 'rowData' =&gt; array('p' =&gt; array('id' =&gt; '1', 'name' =&gt; 'test'), 'c' =&gt; array('latitude' =&gt; '233.234342', 'longitude' =&gt; '-232.23232323232', 'id' =&gt; '2')), 'dqlAlias' =&gt; 'c', 'data' =&gt; array('latitude' =&gt; '233.234342', 'longitude' =&gt; '-232.23232323232', 'id' =&gt; '2'), 'entityName' =&gt; 'LeoFoodRadarBundle:Coordinate', 'parentAlias' =&gt; 'p', 'path' =&gt; 'p.c', 'parentObject' =&gt; object(PlaceMarker), 'parentClass' =&gt; object(ClassMetadata), 'oid' =&gt; '000000003e34db9d00000000492221b6', 'relationField' =&gt; 'coordinate', 'relation' =&gt; array('fieldName' =&gt; 'coordinate', 'targetEntity' =&gt; 'Leo\FoodRadarBundle\Entity\Coordinate', 'joinColumns' =&gt; array(array('name' =&gt; 'coordinate_id', 'unique' =&gt; true, 'nullable' =&gt; true, 'onDelete' =&gt; null, 'columnDefinition' =&gt; null, 'referencedColumnName' =&gt; 'id')), 'mappedBy' =&gt; null, 'inversedBy' =&gt; null, 'cascade' =&gt; array(), 'orphanRemoval' =&gt; false, 'fetch' =&gt; '2', 'type' =&gt; '1', 'isOwningSide' =&gt; true, 'sourceEntity' =&gt; 'Leo\FoodRadarBundle\Entity\PlaceMarker', 'isCascadeRemove' =&gt; false, 'isCascadePersist' =&gt; false, 'isCascadeRefresh' =&gt; false, 'isCascadeMerge' =&gt; false, 'isCascadeDetach' =&gt; false, 'sourceToTargetKeyColumns' =&gt; array(*DEEP NESTED ARRAY*), 'joinColumnFieldNames' =&gt; array(*DEEP NESTED ARRAY*), 'targetToSourceKeyColumns' =&gt; array(*DEEP NESTED ARRAY*)), 'reflField' =&gt; object(ReflectionProperty), 'reflFieldValue' =&gt; null, 'element' =&gt; object(Coordinate), 'entityKey' =&gt; '0', 'resultKey' =&gt; '0'))
  in /Volumes/DATA/LEO/Sites/FoodRadar/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php at line 427  -+
  </code></pre>