简体   繁体   English

Doctrine2和Symfony2-为什么这个吸气剂弄乱了所有东西?

[英]Doctrine2 and Symfony2 - Why this getter mess all the things up?

This snippet of code is driving me crazy. 这段代码使我发疯。

Suppose that entity on which I've done all this operation have all the members that I recall with getters (either on db that on class file; moreover, onto db, all values were inserted). 假设我完成了所有此操作的实体拥有我用getter调用过的所有成员(或者在db上在类文件上;或者在db上插入了所有值)。

$this->logger->debug('INV ROOM RATES CAPACITY - $ROOM ID: '.$camera->getId());
$this->logger->debug('INV ROOM RATES CAPACITY - $ROOMCAPACITY: .$camera->getCapienza());
$this->logger->debug('INV ROOM RATES CAPACITY - CAMERA DB ID: '.$camera->getId());

This outputs the following 输出以下内容

[2013-02-11 14:17:32] app.DEBUG: INV ROOM RATES CAPACITY - $ROOM ID: 14 [] []
[2013-02-11 14:17:32] app.DEBUG: INV ROOM RATES CAPACITY - $ROOMCAPACITY:  [] []
[2013-02-11 14:17:32] app.DEBUG: INV ROOM RATES CAPACITY - CAMERA DB ID:  [] []

It seems that ->getCapienza() method is messing all the things up ( second getter on the same object, doesn't return previous value ). 似乎->getCapienza()方法搞砸了所有事情( 同一对象上的第二个getter,不返回先前的值 )。 Obviously, no error or exceptions are raised. 显然,不会引发任何错误或异常。

What's going on here? 这里发生了什么? Any ideas? 有任何想法吗? I'm stuck since hours .... 我被困了几个小时....

EDIT 编辑

public function getCapienza()
{
    return $this->capienza;
}

Since you just told me that you are clearing the EntityManager sometimes, I digged into it a bit further. 由于您只是告诉我您有时会清除EntityManager,因此我对其进行了进一步的研究。

It is a known issue that will be fixed in Doctrine ORM 2.4 when https://github.com/doctrine/doctrine2/pull/406 is merged. 合并https://github.com/doctrine/doctrine2/pull/406时,此问题将在Doctrine ORM 2.4中修复。

The issue happens because of following piece of code: https://github.com/doctrine/doctrine2/blob/2.3.2/lib/Doctrine/ORM/UnitOfWork.php#L1724-L1780 发生此问题是因为以下代码段: https : //github.com/doctrine/doctrine2/blob/2.3.2/lib/Doctrine/ORM/UnitOfWork.php#L1724-L1780

Basically, it is impossible to merge or generally use proxies that are detached from an EntityManager (you should have lazy-loaded them before). 基本上,不可能合并或通常使用与EntityManager分离的代理(您之前应该先延迟加载它们)。

The problem you are experiencing is related with http://www.doctrine-project.org/jira/browse/DDC-1734 您遇到的问题与http://www.doctrine-project.org/jira/browse/DDC-1734有关

A temporary solution is to re-fetch the data you want to use instead of recycling detached instances. 临时解决方案是重新获取要使用的数据,而不是回收分离的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM