I use Doctrine 2 and want to use optimistic locking. It fails with an OptimisticLockException
and the error message is The optimistic lock failed, version 1 was expected, but is actually
. Please not, that the error message stops after the "actually". It seems Doctrine is not able to determine the version of the entity.
My simplified entity code is:
<?php
declare(encoding='UTF-8');
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table( name = "person" )
*/
class Person extends Entity {
/**
* @param \string $firstName
*/
public function __constructor( $firstName ) {
parent::__constructor();
$this->id = null;
$this->revision = 0;
$this->setFirstName( $firstName );
}
/**
* @return int|null The id of the entity
*/
public function getId() {
return $this->id;
}
/**
* @return int The revision of the entity
*/
public function getRevision() {
return $this->revision;
}
/**
* @return \string The first name
*/
public function getFirstName() {
return $this->firstName;
}
/**
* @param \string $newFirstName The new first name
* @return Person The object itsself for function chaining
*/
public function setFirstName( $newFirstName ) {
$this->firstName = $newFirstName;
return $this;
}
/**
* @ORM\Id
* @ORM\Column( name = "id", type = "integer" )
* @ORM\GeneratedValue( strategy = "SEQUENCE" )
* @var int
*/
protected $id = null;
/**
* @ORM\Version
* @ORM\Column( name = "rev", type = "integer" )
* @var integer
*/
protected $revision = null;
/**
* @ORM\Column( name = "firstname", type = "string", nullable = false )
* @var \string
*/
protected $firstName = null;
}
?>
Further note, that the correct revision (or version) is loaded into the entity. It equals 1 and can be obtained by getRevision()
. Hence, it is not a database error.
The code that triggers the exception is:
$em = $this->getDoctrine()->getManager();
$rep = $this->getDoctrine()->getRepository('HEKdbBundle:Person');
$person = $rep->find( $id );
$rev = $person->getRevision();
$em->lock( $person, LockMode::OPTIMISTIC, $rev );
The (shortened) backtrace is:
at
OptimisticLockException ::lockFailedVersionMismatch (object(Person), '1', null)
in
/srv/www/matthiasn/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php
at line 2320at
UnitOfWork ->lock (object(Person), '1', '1')
in
/srv/www/matthiasn/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php
at line 747at
EntityManager ->lock (object(Person), '1', '1')
in
/srv/www/matthiasn/src/HEK/HEKdbBundle/Controller/PersonController.php
at line 173
As one can see, it is not a problem of the $rev
variable. It perfectly equals 1. Actually line 2317 of UnitOfWork.php
$entityVersion = $class->reflFields[$class->versionField]->getValue($entity);
fails. $entityVersion
equals null
. But I do not know why, because the partial expression $class->versionField
is "revsion". So it is not a problem of the annotation of my entity.
In case anybody can make some sense out of it, here is the var_dump
output of $class$
:
object(Doctrine\ORM\Mapping\ClassMetadata)[290] public 'name' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) public 'namespace' => string 'HEK\HEKdbBundle\Entity' (length=22) public 'rootEntityName' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) public 'customGeneratorDefinition' => null public 'customRepositoryClassName' => null public 'isMappedSuperclass' => boolean false public 'parentClasses' => array (size=0) empty public 'subClasses' => array (size=0) empty public 'namedQueries' => array (size=0) empty public 'namedNativeQueries' => array (size=0) empty public 'sqlResultSetMappings' => array (size=0) empty public 'identifier' => array (size=1) 0 => string 'id' (length=2) public 'inheritanceType' => int 1 public 'generatorType' => int 2 public 'fieldMappings' => array (size=6) 'id' => array (size=9) 'fieldName' => string 'id' (length=2) 'type' => string 'integer' (length=7) 'scale' => int 0 'length' => null 'unique' => boolean false 'nullable' => boolean false 'precision' => int 0 'columnName' => string 'id' (length=2) 'id' => boolean true 'revision' => array (size=9) 'fieldName' => string 'revision' (length=8) 'type' => string 'integer' (length=7) 'scale' => int 0 'length' => null 'unique' => boolean false 'nullable' => boolean false 'precision' => int 0 'columnName' => string 'rev' (length=3) 'default' => int 1 'firstName' => array (size=8) 'fieldName' => string 'firstName' (length=9) 'type' => string 'string' (length=6) 'scale' => int 0 'length' => null 'unique' => boolean false 'nullable' => boolean false 'precision' => int 0 'columnName' => string 'firstname' (length=9) 'lastName' => array (size=8) 'fieldName' => string 'lastName' (length=8) 'type' => string 'string' (length=6) 'scale' => int 0 'length' => null 'unique' => boolean false 'nullable' => boolean false 'precision' => int 0 'columnName' => string 'lastname' (length=8) 'birthday' => array (size=8) 'fieldName' => string 'birthday' (length=8) 'type' => string 'date' (length=4) 'scale' => int 0 'length' => null 'unique' => boolean false 'nullable' => boolean true 'precision' => int 0 'columnName' => string 'birthday' (length=8) 'comment' => array (size=8) 'fieldName' => string 'comment' (length=7) 'type' => string 'text' (length=4) 'scale' => int 0 'length' => null 'unique' => boolean false 'nullable' => boolean true 'precision' => int 0 'columnName' => string 'comment' (length=7) public 'fieldNames' => array (size=6) 'id' => string 'id' (length=2) 'rev' => string 'revision' (length=8) 'firstname' => string 'firstName' (length=9) 'lastname' => string 'lastName' (length=8) 'birthday' => string 'birthday' (length=8) 'comment' => string 'comment' (length=7) public 'columnNames' => array (size=6) 'id' => string 'id' (length=2) 'revision' => string 'rev' (length=3) 'firstName' => string 'firstname' (length=9) 'lastName' => string 'lastname' (length=8) 'birthday' => string 'birthday' (length=8) 'comment' => string 'comment' (length=7) public 'discriminatorValue' => null public 'discriminatorMap' => array (size=0) empty public 'discriminatorColumn' => null public 'table' => array (size=2) 'name' => string 'person' (length=6) 'options' => array (size=0) empty public 'lifecycleCallbacks' => array (size=0) empty public 'entityListeners' => array (size=0) empty public 'associationMappings' => array (size=18) 'title' => array (size=19) 'fieldName' => string 'title' (length=5) 'joinColumns' => array (size=1) ... 'cascade' => array (size=0) ... 'inversedBy' => null 'targetEntity' => string 'HEK\HEKdbBundle\Entity\Title' (length=28) 'fetch' => int 2 'type' => int 2 'mappedBy' => null 'isOwningSide' => boolean true 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'sourceToTargetKeyColumns' => array (size=1) ... 'joinColumnFieldNames' => array (size=1) ... 'targetToSourceKeyColumns' => array (size=1) ... 'orphanRemoval' => boolean false 'gender' => array (size=19) 'fieldName' => string 'gender' (length=6) 'joinColumns' => array (size=1) ... 'cascade' => array (size=0) ... 'inversedBy' => null 'targetEntity' => string 'HEK\HEKdbBundle\Entity\Gender' (length=29) 'fetch' => int 2 'type' => int 2 'mappedBy' => null 'isOwningSide' => boolean true 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'sourceToTargetKeyColumns' => array (size=1) ... 'joinColumnFieldNames' => array (size=1) ... 'targetToSourceKeyColumns' => array (size=1) ... 'orphanRemoval' => boolean false 'country' => array (size=19) 'fieldName' => string 'country' (length=7) 'joinColumns' => array (size=1) ... 'cascade' => array (size=0) ... 'inversedBy' => null 'targetEntity' => string 'HEK\HEKdbBundle\Entity\Country' (length=30) 'fetch' => int 2 'type' => int 2 'mappedBy' => null 'isOwningSide' => boolean true 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'sourceToTargetKeyColumns' => array (size=1) ... 'joinColumnFieldNames' => array (size=1) ... 'targetToSourceKeyColumns' => array (size=1) ... 'orphanRemoval' => boolean false 'familyStatus' => array (size=19) 'fieldName' => string 'familyStatus' (length=12) 'joinColumns' => array (size=1) ... 'cascade' => array (size=0) ... 'inversedBy' => null 'targetEntity' => string 'HEK\HEKdbBundle\Entity\FamilyStatus' (length=35) 'fetch' => int 2 'type' => int 2 'mappedBy' => null 'isOwningSide' => boolean true 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'sourceToTargetKeyColumns' => array (size=1) ... 'joinColumnFieldNames' => array (size=1) ... 'targetToSourceKeyColumns' => array (size=1) ... 'orphanRemoval' => boolean false 'religion' => array (size=19) 'fieldName' => string 'religion' (length=8) 'joinColumns' => array (size=1) ... 'cascade' => array (size=0) ... 'inversedBy' => null 'targetEntity' => string 'HEK\HEKdbBundle\Entity\Religion' (length=31) 'fetch' => int 2 'type' => int 2 'mappedBy' => null 'isOwningSide' => boolean true 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'sourceToTargetKeyColumns' => array (size=1) ... 'joinColumnFieldNames' => array (size=1) ... 'targetToSourceKeyColumns' => array (size=1) ... 'orphanRemoval' => boolean false 'preferredPostalAddress' => array (size=19) 'fieldName' => string 'preferredPostalAddress' (length=22) 'targetEntity' => string 'HEK\HEKdbBundle\Entity\PostalAddress' (length=36) 'joinColumns' => array (size=1) ... 'mappedBy' => null 'inversedBy' => null 'cascade' => array (size=0) ... 'orphanRemoval' => boolean false 'fetch' => int 2 'type' => int 1 'isOwningSide' => boolean true 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'sourceToTargetKeyColumns' => array (size=1) ... 'joinColumnFieldNames' => array (size=1) ... 'targetToSourceKeyColumns' => array (size=1) ... 'postalAddresses' => array (size=15) 'fieldName' => string 'postalAddresses' (length=15) 'mappedBy' => string 'person' (length=6) 'targetEntity' => string 'HEK\HEKdbBundle\Entity\PostalAddress' (length=36) 'cascade' => array (size=0) ... 'orphanRemoval' => boolean false 'fetch' => int 2 'type' => int 4 'inversedBy' => null 'isOwningSide' => boolean false 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'preferredEMailAddress' => array (size=19) 'fieldName' => string 'preferredEMailAddress' (length=21) 'targetEntity' => string 'HEK\HEKdbBundle\Entity\EMailAddress' (length=35) 'joinColumns' => array (size=1) ... 'mappedBy' => null 'inversedBy' => null 'cascade' => array (size=0) ... 'orphanRemoval' => boolean false 'fetch' => int 2 'type' => int 1 'isOwningSide' => boolean true 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'sourceToTargetKeyColumns' => array (size=1) ... 'joinColumnFieldNames' => array (size=1) ... 'targetToSourceKeyColumns' => array (size=1) ... 'eMailAddresses' => array (size=15) 'fieldName' => string 'eMailAddresses' (length=14) 'mappedBy' => string 'person' (length=6) 'targetEntity' => string 'HEK\HEKdbBundle\Entity\EMailAddress' (length=35) 'cascade' => array (size=0) ... 'orphanRemoval' => boolean false 'fetch' => int 2 'type' => int 4 'inversedBy' => null 'isOwningSide' => boolean false 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'preferredTelephoneNumber' => array (size=19) 'fieldName' => string 'preferredTelephoneNumber' (length=24) 'targetEntity' => string 'HEK\HEKdbBundle\Entity\TelephoneNumber' (length=38) 'joinColumns' => array (size=1) ... 'mappedBy' => null 'inversedBy' => null 'cascade' => array (size=0) ... 'orphanRemoval' => boolean false 'fetch' => int 2 'type' => int 1 'isOwningSide' => boolean true 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'sourceToTargetKeyColumns' => array (size=1) ... 'joinColumnFieldNames' => array (size=1) ... 'targetToSourceKeyColumns' => array (size=1) ... 'telephoneNumbers' => array (size=15) 'fieldName' => string 'telephoneNumbers' (length=16) 'mappedBy' => string 'person' (length=6) 'targetEntity' => string 'HEK\HEKdbBundle\Entity\TelephoneNumber' (length=38) 'cascade' => array (size=0) ... 'orphanRemoval' => boolean false 'fetch' => int 2 'type' => int 4 'inversedBy' => null 'isOwningSide' => boolean false 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'bankAccounts' => array (size=15) 'fieldName' => string 'bankAccounts' (length=12) 'mappedBy' => string 'person' (length=6) 'targetEntity' => string 'HEK\HEKdbBundle\Entity\BankAccount' (length=34) 'cascade' => array (size=0) ... 'orphanRemoval' => boolean false 'fetch' => int 2 'type' => int 4 'inversedBy' => null 'isOwningSide' => boolean false 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'contracts' => array (size=15) 'fieldName' => string 'contracts' (length=9) 'mappedBy' => string 'person' (length=6) 'targetEntity' => string 'HEK\HEKdbBundle\Entity\AbstractContract' (length=39) 'cascade' => array (size=0) ... 'orphanRemoval' => boolean false 'fetch' => int 2 'type' => int 4 'inversedBy' => null 'isOwningSide' => boolean false 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'rentalUnitAllocations' => array (size=15) 'fieldName' => string 'rentalUnitAllocations' (length=21) 'mappedBy' => string 'person' (length=6) 'targetEntity' => string 'HEK\HEKdbBundle\Entity\RentalUnitAllocation' (length=43) 'cascade' => array (size=0) ... 'orphanRemoval' => boolean false 'fetch' => int 2 'type' => int 4 'inversedBy' => null 'isOwningSide' => boolean false 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'major' => array (size=19) 'fieldName' => string 'major' (length=5) 'joinColumns' => array (size=1) ... 'cascade' => array (size=0) ... 'inversedBy' => null 'targetEntity' => string 'HEK\HEKdbBundle\Entity\Major' (length=28) 'fetch' => int 2 'type' => int 2 'mappedBy' => null 'isOwningSide' => boolean true 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'sourceToTargetKeyColumns' => array (size=1) ... 'joinColumnFieldNames' => array (size=1) ... 'targetToSourceKeyColumns' => array (size=1) ... 'orphanRemoval' => boolean false 'users' => array (size=15) 'fieldName' => string 'users' (length=5) 'mappedBy' => string 'person' (length=6) 'targetEntity' => string 'HEK\HEKdbBundle\Entity\User' (length=27) 'cascade' => array (size=0) ... 'orphanRemoval' => boolean false 'fetch' => int 2 'type' => int 4 'inversedBy' => null 'isOwningSide' => boolean false 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'tutoriatMemberships' => array (size=15) 'fieldName' => string 'tutoriatMemberships' (length=19) 'mappedBy' => string 'person' (length=6) 'targetEntity' => string 'HEK\HEKdbBundle\Entity\TutoriatMembership' (length=41) 'cascade' => array (size=0) ... 'orphanRemoval' => boolean false 'fetch' => int 2 'type' => int 4 'inversedBy' => null 'isOwningSide' => boolean false 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'image' => array (size=19) 'fieldName' => string 'image' (length=5) 'targetEntity' => string 'HEK\HEKdbBundle\Entity\Image' (length=28) 'joinColumns' => array (size=1) ... 'mappedBy' => null 'inversedBy' => null 'cascade' => array (size=0) ... 'orphanRemoval' => boolean false 'fetch' => int 2 'type' => int 1 'isOwningSide' => boolean true 'sourceEntity' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'isCascadeRemove' => boolean false 'isCascadePersist' => boolean false 'isCascadeRefresh' => boolean false 'isCascadeMerge' => boolean false 'isCascadeDetach' => boolean false 'sourceToTargetKeyColumns' => array (size=1) ... 'joinColumnFieldNames' => array (size=1) ... 'targetToSourceKeyColumns' => array (size=1) ... public 'isIdentifierComposite' => boolean false public 'containsForeignIdentifier' => boolean false public 'idGenerator' => object(Doctrine\ORM\Id\SequenceGenerator)[405] private '_allocationSize' => int 1 private '_sequenceName' => string 'person_id_seq' (length=13) private '_nextValue' => int 0 private '_maxValue' => null public 'sequenceGeneratorDefinition' => array (size=3) 'sequenceName' => string 'person_id_seq' (length=13) 'allocationSize' => int 1 'initialValue' => int 1 public 'tableGeneratorDefinition' => null public 'changeTrackingPolicy' => int 3 public 'isVersioned' => boolean true public 'versionField' => string 'revision' (length=8) public 'reflClass' => object(ReflectionClass)[260] public 'name' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) public 'isReadOnly' => boolean false protected 'namingStrategy' => object(Doctrine\ORM\Mapping\DefaultNamingStrategy)[118] public 'reflFields' => array (size=24) 'id' => object(ReflectionProperty)[285] public 'name' => string 'id' (length=2) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'revision' => object(ReflectionProperty)[404] public 'name' => string 'revision' (length=8) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'firstName' => object(ReflectionProperty)[403] public 'name' => string 'firstName' (length=9) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'lastName' => object(ReflectionProperty)[402] public 'name' => string 'lastName' (length=8) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'birthday' => object(ReflectionProperty)[401] public 'name' => string 'birthday' (length=8) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'comment' => object(ReflectionProperty)[400] public 'name' => string 'comment' (length=7) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'title' => object(ReflectionProperty)[399] public 'name' => string 'title' (length=5) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'gender' => object(ReflectionProperty)[398] public 'name' => string 'gender' (length=6) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'country' => object(ReflectionProperty)[397] public 'name' => string 'country' (length=7) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'familyStatus' => object(ReflectionProperty)[396] public 'name' => string 'familyStatus' (length=12) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'religion' => object(ReflectionProperty)[395] public 'name' => string 'religion' (length=8) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'preferredPostalAddress' => object(ReflectionProperty)[394] public 'name' => string 'preferredPostalAddress' (length=22) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'postalAddresses' => object(ReflectionProperty)[393] public 'name' => string 'postalAddresses' (length=15) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'preferredEMailAddress' => object(ReflectionProperty)[392] public 'name' => string 'preferredEMailAddress' (length=21) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'eMailAddresses' => object(ReflectionProperty)[391] public 'name' => string 'eMailAddresses' (length=14) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'preferredTelephoneNumber' => object(ReflectionProperty)[390] public 'name' => string 'preferredTelephoneNumber' (length=24) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'telephoneNumbers' => object(ReflectionProperty)[389] public 'name' => string 'telephoneNumbers' (length=16) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'bankAccounts' => object(ReflectionProperty)[388] public 'name' => string 'bankAccounts' (length=12) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'contracts' => object(ReflectionProperty)[387] public 'name' => string 'contracts' (length=9) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'rentalUnitAllocations' => object(ReflectionProperty)[386] public 'name' => string 'rentalUnitAllocations' (length=21) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'major' => object(ReflectionProperty)[385] public 'name' => string 'major' (length=5) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'users' => object(ReflectionProperty)[384] public 'name' => string 'users' (length=5) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'tutoriatMemberships' => object(ReflectionProperty)[383] public 'name' => string 'tutoriatMemberships' (length=19) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) 'image' => object(ReflectionProperty)[382] public 'name' => string 'image' (length=5) public 'class' => string 'HEK\HEKdbBundle\Entity\Person' (length=29) private '_prototype' (Doctrine\ORM\Mapping\ClassMetadataInfo) => null
The solution was trivial. Lazy loading tricked me. It seems that
->find
does not really load the entity from database, but that this is postponed until one access the first attribute of the entity. If I insert a$person->getFoo()
, whereby "Foo" denotes any arbitrary, valid property, after the->find
and before the->lock
it works as expected.