【发布时间】:2012-03-16 11:34:36
【问题描述】:
学说 2.1 版
我坚持了很多对象,这就是为什么我必须在$this->entityManager->flush() 之后执行$this->entityManager->clear(),但这会导致一个众所周知的错误:
异常:“通过关系发现了一个新实体 'Entities\A#B' 未配置为级联持久化操作 对于实体:实体\B@00000000550760cc00000000b0edf71c。明确地 持久化新实体或配置级联持久化操作 关系。如果您无法找出是哪个实体导致 问题实现 'Entities\B#__toString()' 以获得线索。”
它适用于第一次冲洗,但不适用于所有其他冲洗。当我评论$this->entityManager->clear();
这是代码示例:
if ($flushCounter % 50 == 0) {
$this->entityManager->flush();
$this->entityManager->clear();
//$this->entityManager->detach($B); <- with these two lines commented I tried to fix the error, but it did not work
//$B = $this->entityManager->find(ENTITY_NAMESPACE . "\B", (int) $B_id);
}
$flushCounter++;
我会重申,注释掉 clear() 函数可以解决问题,但我不想这样做,除非有更好的方法来管理内存
【问题讨论】:
-
您似乎正在更改关联中的实体,但在关联的反面。因此,当您尝试保留拥有方时,由于没有设置
CASCADE: persist,它会引发错误。
标签: php memory-management doctrine-orm