[DDC-2155] problem with DQL and cache Created: 18/Nov/12  Updated: 25/Nov/12  Resolved: 25/Nov/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: DQL, ORM
Affects Version/s: 2.3
Fix Version/s: None
Security Level: All

Type: Bug Priority: Critical
Reporter: gabriel sancho Assignee: Benjamin Eberlei
Resolution: Invalid Votes: 0
Labels: cache, dql

linux , php 5.4.8, mysql 5.5.28


I have a problem when I get database records through a query DQL
and then they are changed by another application
If I repeat the query, Doctrine always return the first value, not the current value of the base


// bootstrap

$cache = new \Doctrine\Common\Cache\ArrayCache();
$config = new Doctrine\ORM\Configuration();
$conn = array(
				'dbname' => $database_name,
				'user' => $cnx_user,
				'password' => $cnx_pass,
				'host' => $cnx_host,
				'driver' => $cnx_type,
				'charset' => 'utf8',
				'driverOptions' => array( 1002 => "SET NAMES 'utf8'" )

			$em = Doctrine\ORM\EntityManager::create($conn, $config);

   $dql = "SELECT s from Register s WHERE s.id = 1";
   $query = $em->createQuery($dql);
// the next line is optional, produces same result
   $res = $query->getResult();
   $orm = reset($res);
   echo " regiter id :".$orm->getId()."  field "$orm->getText()."\n";


I run this code in a terminal, and then edit the registry (field text), but the terminal still shows the same result

Comment by Benjamin Eberlei [ 25/Nov/12 ]

Doctrine uses an IdentityMap pattern which leads to this issue.

You need to call "EntityManager#clear()" to clean the in memory cache of Doctrine and fetch records from the database again. or call "EntityManager#refresh($entity)"

Generated at Mon Aug 31 05:10:47 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.