乐观锁定失败,因为Doctrine无法确定版本 [英] Optimistic locking fails because Doctrine cannot determine version

查看:258
本文介绍了乐观锁定失败,因为Doctrine无法确定版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用Doctrine 2,并希望使用乐观锁定。它失败,并显示 OptimisticLockException ,错误消息为乐观锁失败,应该是版本1,但实际上是。请不要,错误消息在实际之后停止。似乎Doctrine无法确定该实体的版本。



我的简化实体代码是:

 <?php 
clarify(encoding ='UTF-8');

使用Doctrine\ORM\Mapping作为ORM;

/ **
* @ ORM\实体
* @ ORM\Table(name = person)
* /
class Person扩展实体{

/ **
* @param \string $ firstName
* /
公共功能__constructor($ firstName){
父级: :__ constructor();
$ this-> id = null;
$ this->修订版= 0;
$ this-> setFirstName($ firstName);
}

/ **
* @return int | null实体的ID
* /
公共函数getId(){
返回$ this-> id;
}

/ **
* @return int实体的修订版
* /
公共函数getRevision(){
return $ this->修订版;
}

/ **
* @return \string名字
* /
公共函数getFirstName(){
return $ this-> firstName;
}

/ **
* @param \string $ newFirstName新名字
* @return Person用于函数链接
的对象本身* /
公共函数setFirstName($ newFirstName){
$ this-> firstName = $ newFirstName;
返回$ this;
}

/ **
* @ ORM\Id
* @ ORM\Column(name = id,type = integer)
* @ ORM\GeneratedValue(strategy = SEQUENCE)
* @var int
* /
protected $ id = null;

/ **
* @ ORM\版本
* @ ORM\Column(name = rev,type = integer)
* @ var integer
* /
protected $ revision = null;

/ **
* @ ORM\Column(name = firstname,type = string,nullable = false)
* @var \string
* /
protected $ firstName = null;
}

?>

另外请注意,正确的修订(或版本)已加载到实体中。它等于1,可以通过 getRevision()获得。因此,这不是数据库错误。



触发异常的代码为:

  $ em = $ this-> getDoctrine()-> getManager(); 
$ rep = $ this-> getDoctrine()-> getRepository(’HEKdbBundle:Person’);
$ person = $ rep-> find($ id);
$ rev = $ person-> getRevision();
$ em-> lock($ person,LockMode :: OPTIMISTIC,$ rev);

(缩短的)回溯是:


  1. at OptimisticLockException :: lockFailedVersionMismatch(object(Person),'1',null)


    $第2320行的 /srv/www/matthiasn/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php 中的b $ b


  2. UnitOfWork->锁定(对象(人(Person),'1','1')

    第747行的 /srv/www/matthiasn/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php 中的

  3. EntityManager处
  4. ->锁定(对象(人), 1, 1)



    /srv/www/matthiasn/src/HEK/HEKdbBundle/Controller/PersonController.php 中173


正如人们所看到的, $ rev不是问题变量。完全等于1。实际上, UnitOfWork.php

第2317行

  $ entityVersion = $ class-> reflFields [$ class-> versionField]-> getValue($ entity); 

失败。 $ entityVersion 等于 null 。但是我不知道为什么,因为部分表达式 $ class-> versionField 是 revsion。因此,这不是我实体的注释问题。



如果任何人都可以理解,这里是 var_dump $ class $ 的输出:

  object(Doctrine\ORM\Mapping\ClassMetadata)[290] public'name'=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29)公共名称空间 =>字符串 HEK\HEKdbBundle\Entity(长度= 22)公共 rootEntityName =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29)公共 customGeneratorDefinition => null public‘customRepositoryClassName’=>空公共‘isMappedSuperclass’=>布尔值false public‘parentClasses’=>数组(大小= 0)为空的公共子类 =>数组(size = 0)空公共‘namedQueries’=>数组(size = 0)空公共‘namedNativeQueries’=>数组(size = 0)空公共‘sqlResultSetMappings’=>数组(大小= 0)为空的公共标识符 =>数组(size = 1)0 =>字符串 id(长度= 2)公共 inheritanceType => int 1 public‘generatorType’=> int 2 public‘fieldMappings’=>数组(size = 6)'id'=>数组(size = 9)‘fieldName’=>字符串 id(长度= 2)类型 =>字符串整数(长度= 7)比例 => int 0‘length’=> null'unique'=>布尔值false'nullable'=>布尔值false'precision'=> int 0‘columnName’=>字符串 id(长度= 2) id =>布尔值true‘revision’=>数组(size = 9)‘fieldName’=>字符串版本(长度= 8)类型 =>字符串整数(长度= 7)比例 => int 0‘length’=> null'unique'=>布尔值false‘nullable’=>布尔值false'precision'=> int 0‘columnName’=>字符串‘rev’(长度= 3)‘默认’=> int 1‘firstName’=>数组(size = 8)‘fieldName’=>字符串名字(长度= 9)类型 =>字符串 string(长度= 6) scale => int 0‘length’=> null'unique'=>布尔值false‘nullable’=>布尔值false'precision'=> int 0‘columnName’=>字符串 firstname(长度= 9) lastName =>数组(size = 8)‘fieldName’=>字符串姓氏(长度= 8)类型 =>字符串 string(长度= 6) scale => int 0‘length’=> null'unique'=>布尔值false‘nullable’=>布尔值false'precision'=> int 0‘columnName’=>字符串姓氏(长度= 8)生日 =>数组(size = 8)‘fieldName’=>字符串 birthday(长度= 8) type =>字符串日期(长度= 4)比例 => int 0‘length’=> null'unique'=>布尔值false‘nullable’=>布尔值true'precision'=> int 0‘columnName’=>字符串 birthday(长度= 8) comment =>数组(size = 8)‘fieldName’=>字符串 comment(长度= 7) type =>字符串 text(长度= 4) scale => int 0‘length’=> null'unique'=>布尔值false‘nullable’=>布尔值true'precision'=> int 0‘columnName’=>字符串注释(长度= 7)公共 fieldNames =>数组(size = 6)'id'=>字符串 id(长度= 2) rev =>字符串版本(长度= 8)名字 =>字符串 firstName(长度= 9) lastname =>字符串姓氏(长度= 8)生日 =>字符串 birthday(长度= 8) comment =>字符串 comment(长度= 7)public columnNames =>数组(size = 6)'id'=>字符串 id(长度= 2)修订 =>字符串‘rev’(长度= 3)‘名字’=>字符串 firstname(长度= 9) lastName =>字符串姓氏(长度= 8)生日 =>字符串 birthday(长度= 8) comment =>字符串'comment'(长度= 7)public'discriminatorValue'=> null公开的 discriminatorMap =>数组(大小= 0)为空,公共为 discriminatorColumn =>空的公共表 =>数组(size = 2)‘名称’=>字符串 person(长度= 6) options =>数组(大小= 0)为空的公共‘lifecycleCallbacks’=>数组(size = 0)空公共‘entityListeners’=>数组(大小= 0)为空的公共 associationMappings =>数组(size = 18)‘title’=>数组(size = 19)‘fieldName’=>字符串 title(长度= 5) joinColumns => array(size = 1)...'cascade'=>数组(size = 0)...‘inversedBy’=> null‘targetEntity’=>字符串 HEK\HEKdbBundle\Entity\Title(长度= 28) fetch => int 2‘type’=> int 2‘mappedBy’=> null'isOwningSide'=>布尔值true‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔值false‘sourceToTargetKeyColumns’=>数组(size = 1)...‘joinColumnFieldNames’=>数组(size = 1)...‘targetToSourceKeyColumns’=> array(size = 1)...‘orphanRemoval’=>布尔值false‘性别’=>数组(size = 19)‘fieldName’=>字符串性别(长度= 6) joinColumns => array(size = 1)...'cascade'=>数组(size = 0)...‘inversedBy’=> null‘targetEntity’=>字符串 HEK\HEKdbBundle\Entity\Gender(长度= 29) fetch => int 2‘type’=> int 2‘mappedBy’=> null'isOwningSide'=>布尔值true‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔值false‘sourceToTargetKeyColumns’=>数组(size = 1)...‘joinColumnFieldNames’=>数组(size = 1)...‘targetToSourceKeyColumns’=> array(size = 1)...‘orphanRemoval’=>布尔值false‘country’=>数组(size = 19)‘fieldName’=>字符串国家(长度= 7) joinColumns => array(size = 1)...'cascade'=>数组(size = 0)...‘inversedBy’=> null‘targetEntity’=>字符串 HEK\HEKdbBundle\Entity\Country(长度= 30) fetch => int 2‘type’=> int 2‘mappedBy’=> null'isOwningSide'=>布尔值true‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false‘isCascadeRefresh’=>布尔值false‘isCascadeMerge’=>布尔值false‘isCascadeDetach’=>布尔值false‘sourceToTargetKeyColumns’=>数组(size = 1)...‘joinColumnFieldNames’=>数组(size = 1)...‘targetToSourceKeyColumns’=> array(size = 1)...‘orphanRemoval’=>布尔值false‘familyStatus’=>数组(size = 19)‘fieldName’=>字符串‘familyStatus’(length = 12)‘joinColumns’=> array(size = 1)...'cascade'=>数组(size = 0)...‘inversedBy’=> null‘targetEntity’=>字符串 HEK\HEKdbBundle\Entity\FamilyStatus(长度= 35) fetch => int 2‘type’=> int 2‘mappedBy’=> null'isOwningSide'=>布尔值true‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔值false‘sourceToTargetKeyColumns’=>数组(size = 1)...‘joinColumnFieldNames’=>数组(size = 1)...‘targetToSourceKeyColumns’=> array(size = 1)...‘orphanRemoval’=>布尔假‘宗教’=>数组(size = 19)‘fieldName’=>字符串宗教(长度= 8) joinColumns => array(size = 1)...'cascade'=>数组(size = 0)...‘inversedBy’=> null‘targetEntity’=>字符串 HEK\HEKdbBundle\Entity\Religion(长度= 31) fetch => int 2‘type’=> int 2‘mappedBy’=> null'isOwningSide'=>布尔值true‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔值false‘sourceToTargetKeyColumns’=>数组(size = 1)...‘joinColumnFieldNames’=>数组(size = 1)...‘targetToSourceKeyColumns’=> array(size = 1)...‘orphanRemoval’=>布尔假‘preferredPostalAddress’=>数组(size = 19)‘fieldName’=>字符串‘preferredPostalAddress’(length = 22)‘targetEntity’=>字符串 HEK\HEKdbBundle\Entity\PostalAddress(长度= 36) joinColumns =>数组(size = 1)...‘mappedBy’=> null‘inversedBy’=> null'cascade'=>数组(size = 0)...‘orphanRemoval’=>布尔值false'fetch'=> int 2‘type’=> int 1‘isOwningSide’=>布尔值true‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔值false‘sourceToTargetKeyColumns’=>数组(size = 1)...‘joinColumnFieldNames’=>数组(size = 1)...‘targetToSourceKeyColumns’=>数组(size = 1)...‘postalAddresses’=>数组(size = 15)‘fieldName’=>字符串 postalAddresses(长度= 15) mappedBy =>字符串人(长度= 6) targetEntity =>字符串 HEK\HEKdbBundle\Entity\PostalAddress(长度= 36)级联 =>数组(size = 0)...‘orphanRemoval’=>布尔值false'fetch'=> int 2‘type’=> int 4‘inversedBy’=> null'isOwningSide'=>布尔值false‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false‘isCascadeRefresh’=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔假‘preferredEMailAddress’=>数组(size = 19)‘fieldName’=>字符串‘preferredEMailAddress’(length = 21)‘targetEntity’=>字符串 HEK\HEKdbBundle\Entity\EMailAddress(长度= 35) joinColumns =>数组(size = 1)...‘mappedBy’=> null‘inversedBy’=> null'cascade'=>数组(size = 0)...‘orphanRemoval’=>布尔值false'fetch'=> int 2‘type’=> int 1‘isOwningSide’=>布尔值true‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔值false‘sourceToTargetKeyColumns’=>数组(size = 1)...‘joinColumnFieldNames’=>数组(size = 1)...‘targetToSourceKeyColumns’=>数组(size = 1)...‘eMailAddresses’=>数组(size = 15)‘fieldName’=>字符串 eMailAddresses(长度= 14) mappedBy =>字符串人(长度= 6) targetEntity =>字符串 HEK\HEKdbBundle\Entity\EMailAddress(长度= 35) cascade =>数组(size = 0)...‘orphanRemoval’=>布尔值false'fetch'=> int 2‘type’=> int 4‘inversedBy’=> null'isOwningSide'=>布尔值false‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔假‘preferredTelephoneNumber’=>数组(size = 19)‘fieldName’=>字符串 preferredTelephoneNumber(长度= 24) targetEntity =>字符串 HEK\HEKdbBundle\Entity\TelephoneNumber(长度= 38) joinColumns =>数组(size = 1)...‘mappedBy’=> null‘inversedBy’=> null'cascade'=>数组(size = 0)...‘orphanRemoval’=>布尔值false'fetch'=> int 2‘type’=> int 1‘isOwningSide’=>布尔值true‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔值false‘sourceToTargetKeyColumns’=>数组(size = 1)...‘joinColumnFieldNames’=>数组(size = 1)...‘targetToSourceKeyColumns’=>数组(size = 1)...‘telephoneNumbers’=>数组(size = 15)‘fieldName’=>字符串 telephoneNumbers(长度= 16) mappedBy =>字符串人(长度= 6) targetEntity =>字符串 HEK\HEKdbBundle\Entity\TelephoneNumber(长度= 38) cascade =>数组(size = 0)...‘orphanRemoval’=>布尔值false'fetch'=> int 2‘type’=> int 4‘inversedBy’=> null'isOwningSide'=>布尔值false‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false‘isCascadeDetach’=>布尔值false‘bankAccounts’=>数组(size = 15)‘fieldName’=>字符串‘bankAccounts’(length = 12)‘mappedBy’=>字符串人(长度= 6) targetEntity =>字符串 HEK\HEKdbBundle\Entity\BankAccount(长度= 34) cascade =>数组(size = 0)...‘orphanRemoval’=>布尔值false'fetch'=> int 2‘type’=> int 4‘inversedBy’=> null'isOwningSide'=>布尔值false‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false‘isCascadeRefresh’=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔值false‘合约’=>数组(size = 15)‘fieldName’=>字符串合约(长度= 9) mappedBy =>字符串人(长度= 6) targetEntity =>字符串 HEK\HEKdbBundle\Entity\AbstractContract(长度= 39)级联 =>数组(size = 0)...‘orphanRemoval’=>布尔值false'fetch'=> int 2‘type’=> int 4‘inversedBy’=> null'isOwningSide'=>布尔值false‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false‘isCascadeDetach’=>布尔值false‘rentalUnitAllocations’=>数组(size = 15)‘fieldName’=>字符串 rentalUnitAllocations(长度= 21) mappedBy =>字符串人(长度= 6) targetEntity =>字符串'HEK\HEKdbBundle\Entity\RentalUnitAllocation'(长度= 43)'cascade'=>数组(size = 0)...‘orphanRemoval’=>布尔值false'fetch'=> int 2‘type’=> int 4‘inversedBy’=> null'isOwningSide'=>布尔值false‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false‘isCascadeRefresh’=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔值false‘major’=>数组(size = 19)‘fieldName’=>字符串‘major’(length = 5)‘joinColumns’=> array(size = 1)...'cascade'=>数组(size = 0)...‘inversedBy’=> null‘targetEntity’=>字符串 HEK\HEKdbBundle\Entity\Major(长度= 28) fetch => int 2‘type’=> int 2‘mappedBy’=> null'isOwningSide'=>布尔值true‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false‘isCascadeDetach’=>布尔值false‘sourceToTargetKeyColumns’=>数组(size = 1)...‘joinColumnFieldNames’=>数组(size = 1)...‘targetToSourceKeyColumns’=> array(size = 1)...‘orphanRemoval’=>布尔值false'users'=>数组(size = 15)‘fieldName’=>字符串 users(长度= 5) mappedBy =>字符串人(长度= 6) targetEntity =>字符串 HEK\HEKdbBundle\Entity\User(长度= 27)级联 =>数组(size = 0)...‘orphanRemoval’=>布尔值false'fetch'=> int 2‘type’=> int 4‘inversedBy’=> null'isOwningSide'=>布尔值false‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔值false‘tutoriatMemberships’=>数组(size = 15)‘fieldName’=>字符串 tutoriatMemberships(长度= 19) mappedBy =>字符串人(长度= 6) targetEntity =>字符串 HEK\HEKdbBundle\Entity\TutoriatMembership(长度= 41) cascade =>数组(size = 0)...‘orphanRemoval’=>布尔值false'fetch'=> int 2‘type’=> int 4‘inversedBy’=> null'isOwningSide'=>布尔值false‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false'isCascadeRefresh'=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔值false‘image’=>数组(size = 19)‘fieldName’=>字符串 image(长度= 5) targetEntity =>字符串 HEK\HEKdbBundle\Entity\Image(长度= 28) joinColumns =>数组(size = 1)...‘mappedBy’=> null‘inversedBy’=> null'cascade'=>数组(size = 0)...‘orphanRemoval’=>布尔值false'fetch'=> int 2‘type’=> int 1‘isOwningSide’=>布尔值true‘sourceEntity’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) isCascadeRemove =>布尔值false‘isCascadePersist’=>布尔值false‘isCascadeRefresh’=>布尔值false‘isCascadeMerge’=>布尔值false'isCascadeDetach'=>布尔值false‘sourceToTargetKeyColumns’=>数组(size = 1)...‘joinColumnFieldNames’=>数组(size = 1)...‘targetToSourceKeyColumns’=>数组(size = 1)... public‘isIdentifierComposite’=>布尔值false public‘containsForeignIdentifier’=>布尔值false public‘idGenerator’=> object(Doctrine\ORM\Id\SequenceGenerator)[405]私有‘_allocationSize’=> int 1私人 _sequenceName =>字符串‘person_id_seq’(length = 13)私人‘_nextValue’=> int 0 private _maxValue => null公开的 sequenceGeneratorDefinition =>数组(size = 3)‘sequenceName’=>字符串‘person_id_seq’(长度= 13)‘allocationSize’=> int 1‘initialValue’=> int 1 public‘tableGeneratorDefinition’=> null公开的 changeTrackingPolicy => int 3 public‘isVersioned’=>布尔值true public‘versionField’=>字符串 revision(长度= 8)public reflClass => object(ReflectionClass)[260]公共名称 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29)公共 isReadOnly =>布尔值false受保护的‘namingStrategy’=> object(Doctrine\ORM\Mapping\DefaultNamingStrategy)[118] public‘reflFields’=>数组(size = 24)'id'=> object(ReflectionProperty)[285]公共名称 =>字符串'id'(length = 2)public'class'=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29)版本 => object(ReflectionProperty)[404]公共名称 =>字符串修订(长度= 8)公共班级 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) firstName => object(ReflectionProperty)[403]公共名称 =>字符串 firstName(长度= 9)公共 class =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) lastName => object(ReflectionProperty)[402]公共名称 =>字符串姓氏(长度= 8)公共类 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29)生日 => object(ReflectionProperty)[401]公共名称 =>字符串生日(长度= 8)公共班级 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) comment => object(ReflectionProperty)[400]公共名称 =>字符串'comment'(长度= 7)public'class'=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) title => object(ReflectionProperty)[399]公共名称 =>字符串 title(长度= 5)公共 class =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) gender => object(ReflectionProperty)[398]公共名称 =>字符串性别(长度= 6)公共班级 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29)国家 => object(ReflectionProperty)[397]公共名称 =>字符串国家(长度= 7)公共类 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) familyStatus => object(ReflectionProperty)[396]公共名称 =>字符串‘familyStatus’(length = 12)public‘class’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29)宗教 => object(ReflectionProperty)[395]公共名称 =>字符串宗教(长度= 8)公共班级 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) preferredPostalAddress => object(ReflectionProperty)[394]公共名称 =>字符串 preferredPostalAddress(长度= 22)公共类 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) postalAddresses => object(ReflectionProperty)[393]公共名称 =>字符串 postalAddresses(长度= 15)公共类 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) preferredEMailAddress => object(ReflectionProperty)[392]公共名称 =>字符串 preferredEMailAddress(length = 21)public class =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) eMailAddresses => object(ReflectionProperty)[391]公共名称 =>字符串‘eMailAddresses’(length = 14)public‘class’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) preferredTelephoneNumber => object(ReflectionProperty)[390]公共名称 =>字符串 preferredTelephoneNumber(长度= 24)公共类 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) telephoneNumbers => object(ReflectionProperty)[389]公共名称 =>字符串 telephoneNumbers(长度= 16)公共类 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) bankAccounts => object(ReflectionProperty)[388]公共名称 =>字符串‘bankAccounts’(length = 12)public‘class’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) contracts => object(ReflectionProperty)[387]公共名称 =>字符串'contracts'(length = 9)public'class'=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) rentalUnitAllocations => object(ReflectionProperty)[386]公共名称 =>字符串‘rentalUnitAllocations’(length = 21)public‘class’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) major => object(ReflectionProperty)[385]公共名称 =>字符串‘major’(length = 5)public‘class’=>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29)用户 => object(ReflectionProperty)[384]公共名称 =>字符串用户(长度= 5)公共类 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) tutoriatMemberships => object(ReflectionProperty)[383]公共名称 =>字符串 tutoriatMemberships(长度= 19)公共课程 =>字符串 HEK\HEKdbBundle\Entity\Person(长度= 29) image => object(ReflectionProperty)[382]公共名称 =>字符串图片(长度= 5)公共类 =>字符串 HEK\HEKdbBundle\实体\人员(长度= 29)私有 _prototype(Doctrine\ORM\Mapping\ClassMetadataInfo)=> null 


解决方案

解决方案很简单。延迟加载欺骗了我。似乎-> find 并没有真正从数据库中加载实体,但是这被推迟到访问实体的第一个属性为止。如果我在-> find <之后插入 $ person-> getFoo(),其中 Foo表示任意有效的属性/ code>并在->锁定之前按预期工作。


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:

  1. at OptimisticLockException ::lockFailedVersionMismatch (object(Person), '1', null)

    in /srv/www/matthiasn/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php at line 2320

  2. at UnitOfWork ->lock (object(Person), '1', '1')

    in /srv/www/matthiasn/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php at line 747

  3. at 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.

这篇关于乐观锁定失败,因为Doctrine无法确定版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆