DDC-2155: problem with DQL and cache #2711

Closed
opened 2026-01-22 14:01:15 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 18, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user gabrielnn77:

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

<?php

// bootstrap

$cache = new \Doctrine\Common\Cache\ArrayCache();
$config = new Doctrine\ORM\Configuration();
$config->setQueryCacheImpl($cache);
$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);




while(true){
   $dql = "SELECT s from Register s WHERE s.id = 1";
   $query = $em->createQuery($dql);
// the next line is optional, produces same result
   $query->useResultCache(false);
   $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

Originally created by @doctrinebot on GitHub (Nov 18, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user gabrielnn77: 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 ``` <?php // bootstrap $cache = new \Doctrine\Common\Cache\ArrayCache(); $config = new Doctrine\ORM\Configuration(); $config->setQueryCacheImpl($cache); $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); ``` ``` while(true){ $dql = "SELECT s from Register s WHERE s.id = 1"; $query = $em->createQuery($dql); // the next line is optional, produces same result $query->useResultCache(false); $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
admin added the Bug label 2026-01-22 14:01:15 +01:00
admin closed this issue 2026-01-22 14:01:15 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 25, 2012):

Comment created by @beberlei:

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)"

@doctrinebot commented on GitHub (Nov 25, 2012): Comment created by @beberlei: 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)"
Author
Owner

@doctrinebot commented on GitHub (Nov 25, 2012):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Nov 25, 2012): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2711