Doctrine find() returning controller
===

I have a method within my controller that takes a deserialized object from JMSSerializerBundle and returns the full object, ready to be persisted. The reason I'm doing this is to return the updated object so, when it's persisted, it doesn't reset everything to the default.

Since my comments aren't being formatted correctly... the `$data` parameter is the object as it is returned by JSMSerializierBundle::deserialize() and it should return (in this case) `Keobi\ModelBundle\Entity\User`.

It's throwing an `ErrorException` on the indicated line and puts this in my log: `Warning: ReflectionProperty::setValue() expects parameter 1 to be object, null given in C:\DevelopmentProjects\keobi-web\vendor\doctrine\lib\Doctrine\ORM\Mapping\ClassMetadata.php line 177 (uncaught exception) at C:\DevelopmentProjects\keobi-web\vendor\symfony\src\Symfony\Component\HttpKernel\Debug\ErrorHandler.php line 65` 

For some reason, the `EntityManager` method `find` is returning (according to `get_class`) `DefaultController`, the controller class for this method. And the `setFieldValue` says it's NULL.

`$em` is definitely `EntityManager` and `$metadata` is definitely `ClassMetadata`. 

I'm at a loss here. No idea how to proceed.

>   protected function processEntity($data)
>   { 
>     $em = $this->getDoctrine()->getEntityManager();
>     $metadata = $em->getClassMetadata(get_class($data));
>     $fqcn = $metadata->getName();
>     $blankEntity = new $fqcn();
>     $id = array();
>     
>     $this->get('logger')->debug('Incoming object type: ' . get_class($data)); # Keobi\ModelBundle\Entity\User
>     $this->get('logger')->debug('Blank entity type: ' . get_class($blankEntity)); # Keobi\ModelBundle\Entity\User
>     $this->get('logger')->debug('FQCN: ' . $fqcn); # Keobi\ModelBundle\Entity\User
>     
>     foreach ($metadata->getIdentifierFieldNames() as $identifier)
>     {
>       $id[$identifier] = $metadata->getFieldValue($data, $identifier);
>       
>       if (!$id[$identifier])
>       {
>         $this->get('logger')->debug(sprintf("Identifer '%s' missing. Assuming the object is new.", $identifier));
>         return $data;
>       }
>     }
>     
>     $entity = $em->find($metadata->getName(), $id);
>     
>     $this->get('logger')->debug(get_class($entity)); # Keobi\RestAPIBundle\DefaultController
>     
>     foreach ($metadata->getFieldNames() as $field)
>     {
>       $value = $metadata->getFieldValue($data, $field);
>       $default = $metadata->getFieldValue($blankEntity, $field);
>       
>       if ($value <> $default)
>       {
>         $metadata->setFieldValue($entity, $field, $value); # <- throws ErrorException
>         $this->get('logger')->debug(sprintf("Updated field '%s' in %s", $field, get_class($entity)));
>       }
>     }
>     
>     return $entity;
>   }