主义2.1版学说2.1 - 实体并不能被持续
我很坚持大量的对象,这就是为什么我有$this->entityManager->flush()
后做$this->entityManager->clear()
,但它会导致一个众所周知的错误:
Exception: "A new entity was found through the relationship 'Entities\A#B' that was not configured to cascade persist operations for entity: Entities\[email protected] Explicitly persist the new entity or configure cascading persist operations on the relationship. If you cannot find out which entity causes the problem implement 'Entities\B#__toString()' to get a clue."
它适用于第一次冲洗,但它不适用于所有其他冲洗。当我评论$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'集合,它会抛出错误。 – 2012-03-19 03:32:11