I have a problem with my doctrine 2.0 proxies not hydrating its entity correctly causing the entities fields to return null when calling themn see below:-
snippet from https://github.com/andyfenna/AJF-IT/blob/master/library/AJFIT/ACL/Factory.php line 60
foreach($arrRoleResources as $roleResource) { //$roleResouces is a proxy entity
$role = $roleResource->getRoleFk(); //
$roleName = $role->getName(); //roleName becomes null even through the pk is populated
}
My project is on git hub https://github.com/andyfenna/AJF-IT
The proxy when generated is saved like library\\AJFIT\\Entity\\Proxy\\AJFITEntityUserRoleResourcesProxy.php
Should the proxy not be saved like library\\AJFIT\\Entity\\Proxy\\UserRoleResourcesProxy.php? or am I missing something?
The proxy class looks like the below and are automatically generated by doctrine.
The UserRoleResources.php entity is saved in library\\AJFIT\\Entity\\
Proxy:- AJFITEntityUserRoleResourcesProxy.php
<?php
namespace AJFIT\Entity\Proxy;
/**
* THIS CLASS WAS GENERATED BY THE DOCTRINE ORM. DO NOT EDIT THIS FILE.
*/
class AJFITEntityUserResourcesProxy extends \AJFIT\Entity\UserResources implements\Doctrine\ORM\Proxy\Proxy
{
private $_entityPersister;
private $_identifier;
public $__isInitialized__ = false;
public function __construct($entityPersister, $identifier)
{
$this->_entityPersister = $entityPersister;
$this->_identifier = $identifier;
}
/** @private */
public function __load()
{
if (!$this->__isInitialized__ && $this->_entityPersister) {
$this->__isInitialized__ = true;
if (method_exists($this, "__wakeup")) {
// call this after __isInitialized__to avoid infinite recursion
// but before loading to emulate what ClassMetadata::newInstance()
// provides.
$this->__wakeup();
}
if ($this->_entityPersister->load($this->_identifier, $this) === null) {
throw new \Doctrine\ORM\EntityNotFoundException();
}
unset($this->_entityPersister, $this->_identifier);
}
}
public function setModule($module)
{
$this->__load();
return parent::setModule($module);
}
public function getModule()
{
$this->__load();
return parent::getModule();
}
public function setController($controller)
{
$this->__load();
return parent::setController($controller);
}
public function getController()
{
$this->__load();
return parent::getController();
}
public function setAction($action)
{
$this->__load();
return parent::setAction($action);
}
public function getAction()
{
$this->__load();
return parent::getAction();
}
public function setName($name)
{
$this->__load();
return parent::setName($name);
}
public function getName()
{
$this->__load();
return parent::getName();
}
public function setRoutename($routename)
{
$this->__load();
return parent::setRoutename($routename);
}
public function getRoutename()
{
$this->__load();
return parent::getRoutename();
}
public function setModifed($modifed)
{
$this->__load();
return parent::setModifed($modifed);
}
public function getModifed()
{
$this->__load();
return parent::getModifed();
}
public function setCreated($created)
{
$this->__load();
return parent::setCreated($created);
}
public function getCreated()
{
$this->__load();
return parent::getCreated();
}
public function getPk()
{
$this->__load();
return parent::getPk();
}
public function __sleep()
{
return array('__isInitialized__', 'module', 'controller', 'action', 'name', 'routename', 'modifed', 'created', 'pk');
}
public function __clone()
{
if (!$this->__isInitialized__ && $this->_entityPersister) {
$this->__isInitialized__ = true;
$class = $this->_entityPersister->getClassMetadata();
$original = $this->_entityPersister->load($this->_identifier);
if ($original === null) {
throw new \Doctrine\ORM\EntityNotFoundException();
}
foreach ($class->reflFields AS $field => $reflProperty) {
$reflProperty->setValue($this, $reflProperty->getValue($original));
}
unset($this->_entityPersister, $this->_identifier);
}
}
}
Entity:- UserRoleResources.php
<?php
namespace AJFIT\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* UserRoleResources
*
* @Table(name="user_role_resources")
* @Entity
*/
class UserRoleResources
{
/**
* @var datetime $modified
*
* @Column(name="modified", type="datetime")
*/
private $modified;
/**
* @var datetime $created
*
* @Column(name="created", type="datetime")
*/
private $created;
/**
* @var integer $pk
*
* @Column(name="pk", type="integer")
* @Id
* @GeneratedValue(strategy="IDENTITY")
*/
private $pk;
/**
* @var serResources
*
* @ManyToOne(targetEntity="UserResources")
* @JoinColumn(name="resources_fk", referencedColumnName="pk")
*/
private $resourcesFk;
/**
* @var UserRoles
*
* @ManyToOne(targetEntity="UserRoles")
* @JoinColumn(name="role_fk", referencedColumnName="pk")
*/
private $roleFk;
public function __construct()
{
$this->roleFk = new ArrayCollection();
}
/**
* Set modified
*
* @param datetime $modified
*/
public function setModified($modified)
{
$this->modified = $modified;
}
/**
* Get modified
*
* @return datetime
*/
public function getModified()
{
return $this->modified;
}
/**
* Set created
*
* @param datetime $created
*/
public function setCreated($created)
{
$this->created = $created;
}
/**
* Get created
*
* @return datetime
*/
public function getCreated()
{
return $this->created;
}
/**
* Get pk
*
* @return integer
*/
public function getPk()
{
return $this->pk;
}
/**
* Set resourcesFk
*
* @param UserResources $resourcesFk
*/
public function setResourcesFk(UserResources $resourcesFk)
{
$this->resourcesFk = $resourcesFk;
}
public function getResourcesFk()
{
return $this->resourcesFk;
}
/**
* Set roleFk
*
* @param UserRoles $roleFk
*/
public function setRoleFk(UserRoles $roleFk)
{
$this->roleFk = $roleFk;
}
public function getRoleFk()
{
return $this->roleFk;
}
}
Does anyone have any ideas? any help in the matter will be mush apprieciated.
Thank-you
I have included the debug steps that I am going through, hope someone knows whats going on:-
Initial break point
Step through to proxy
Step through to proxy load
Hyradation of entity
Return to proxy
Step into entity
Return to caller (you can see that the variable $roleName is null why??)
I had faced similar issue ie one of my entity property is not storing its value in Database
Root cause was its annotation was incorrect (ie somehow backtick came into annotation)
/**` (this backtick is culprit)
* @var string
*
* @ORM\Column(name="condition", type="text", nullable=true)
*/
If some one facing similar issue, first need to check its annotation part
ps: I know this question is year old but i am answer this because it may help others
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.