主義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