Hydrator giving wrong entity #5139

Open
opened 2026-01-22 14:59:20 +01:00 by admin · 3 comments
Owner

Originally created by @AntonioCS on GitHub (Jun 4, 2016).

Hey,

I am working on a legacy symfony2 project with doctrine2 (components at the bottom)
I had to create a simple cache system using a table.

The table has the following data:

id;key;value;is_serialized;created;ttl
1;test;1111111111111111111;0;2016-06-03 22:46:58;\N
2;aaaaatest2;22222222222222222222;0;2016-06-03 22:46:58;\N
3;1212aaaaa;3333333333333333333;0;2016-06-03 22:46:58;\N
4;dd23fdsdaaaaa;4444444444444444444;0;2016-06-03 22:46:58;\N

I have the following code to retrieve data (this is an internal method used by the public method fetch):

  private function fetchEntity($key)
        {
            /* @var $res Storage */
            $res = $this->getEntityManager()
                ->getRepository(Storage::class)
                ->findOneBy(['key' => $key]);

            if ($res) {
                return $res;
            }

            return null;
        }

The problem I have is that given the following code:

       var_dump($storage->fetch('aaaaatest2'));
        var_dump($storage->fetch('1212aaaaa'));
        var_dump($storage->fetch('dd23fdsdaaaaa'));
        var_dump($storage->fetch('11dd23fdsdaaaaa'));

I will ALWAYS get the value of the first fetch. In this case the value is 22222222222222222222 for all the calls.

I can see the query being formed in mysql log and the query is correct. If I grab the query from the log and run it in mysql I get the value I want.

From what I can see (using a debugger) is that on file vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\BasicEntityPersister.php line 699 I get the wrong value. The code is:

 $hydrator = $this->_em->newHydrator($this->_selectJoinSql ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT);
$entities = $hydrator->hydrateAll($stmt, $this->_rsm, $hints);

What am I doing wrong here????

Here are my doctrine2 configs:


doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8
        types:
            json: Sonata\Doctrine\Types\JsonType
            point: PitchBundle\ORM\PointType
        mapping_types:
            point: string
            enum: string

    orm:
        entity_managers:
            default:
                auto_mapping: true
                dql:
                    numeric_functions:
                        point_str: PitchBundle\ORM\PointStr
                        distance: PitchBundle\ORM\Distance
        auto_generate_proxy_classes: %kernel.debug%

There are the doctrine components I am using:

doctrine/annotations                     v1.1.2 
doctrine/cache                           v1.2.0 
doctrine/collections                     dev-master bcb5377 
doctrine/common                          2.4.x-dev c94d6ff 
doctrine/data-fixtures                   dev-master 8ffac1c 
doctrine/dbal                            2.3.x-dev 59c310b 
doctrine/doctrine-bundle                 dev-master a41322d
doctrine/doctrine-fixtures-bundle        dev-master 3caec48
doctrine/doctrine-migrations-bundle      dev-master 1a7f58d 
doctrine/inflector                       dev-master 8b4b3cc
doctrine/lexer                           dev-master bc0e1f0
doctrine/migrations                      dev-master e960224 
doctrine/orm                             2.3.x-dev 66d8b43
Originally created by @AntonioCS on GitHub (Jun 4, 2016). Hey, I am working on a legacy symfony2 project with doctrine2 (components at the bottom) I had to create a simple cache system using a table. The table has the following data: ``` id;key;value;is_serialized;created;ttl 1;test;1111111111111111111;0;2016-06-03 22:46:58;\N 2;aaaaatest2;22222222222222222222;0;2016-06-03 22:46:58;\N 3;1212aaaaa;3333333333333333333;0;2016-06-03 22:46:58;\N 4;dd23fdsdaaaaa;4444444444444444444;0;2016-06-03 22:46:58;\N ``` I have the following code to retrieve data (this is an internal method used by the public method fetch): ``` private function fetchEntity($key) { /* @var $res Storage */ $res = $this->getEntityManager() ->getRepository(Storage::class) ->findOneBy(['key' => $key]); if ($res) { return $res; } return null; } ``` The problem I have is that given the following code: ``` var_dump($storage->fetch('aaaaatest2')); var_dump($storage->fetch('1212aaaaa')); var_dump($storage->fetch('dd23fdsdaaaaa')); var_dump($storage->fetch('11dd23fdsdaaaaa')); ``` I will ALWAYS get the value of the first fetch. In this case the value is 22222222222222222222 for all the calls. I can see the query being formed in mysql log and the query is correct. If I grab the query from the log and run it in mysql I get the value I want. From what I can see (using a debugger) is that on file vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\BasicEntityPersister.php line 699 I get the wrong value. The code is: ``` $hydrator = $this->_em->newHydrator($this->_selectJoinSql ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT); $entities = $hydrator->hydrateAll($stmt, $this->_rsm, $hints); ``` What am I doing wrong here???? Here are my doctrine2 configs: ``` doctrine: dbal: driver: %database_driver% host: %database_host% port: %database_port% dbname: %database_name% user: %database_user% password: %database_password% charset: UTF8 types: json: Sonata\Doctrine\Types\JsonType point: PitchBundle\ORM\PointType mapping_types: point: string enum: string orm: entity_managers: default: auto_mapping: true dql: numeric_functions: point_str: PitchBundle\ORM\PointStr distance: PitchBundle\ORM\Distance auto_generate_proxy_classes: %kernel.debug% ``` There are the doctrine components I am using: ``` doctrine/annotations v1.1.2 doctrine/cache v1.2.0 doctrine/collections dev-master bcb5377 doctrine/common 2.4.x-dev c94d6ff doctrine/data-fixtures dev-master 8ffac1c doctrine/dbal 2.3.x-dev 59c310b doctrine/doctrine-bundle dev-master a41322d doctrine/doctrine-fixtures-bundle dev-master 3caec48 doctrine/doctrine-migrations-bundle dev-master 1a7f58d doctrine/inflector dev-master 8b4b3cc doctrine/lexer dev-master bc0e1f0 doctrine/migrations dev-master e960224 doctrine/orm 2.3.x-dev 66d8b43 ```
admin added the Missing Tests label 2026-01-22 14:59:20 +01:00
Author
Owner

@TomasVotruba commented on GitHub (Jun 4, 2016):

Not sure if it matters, but method name is fetchEntity() and in the example code you use fetch().

@TomasVotruba commented on GitHub (Jun 4, 2016): Not sure if it matters, but method name is `fetchEntity()` and in the example code you use `fetch()`.
Author
Owner

@Ocramius commented on GitHub (Jun 4, 2016):

@TomasVotruba marking it as "missing tests" - can't reproduce it with this info, sorry.

@Ocramius commented on GitHub (Jun 4, 2016): @TomasVotruba marking it as "missing tests" - can't reproduce it with this info, sorry.
Author
Owner

@Ocramius commented on GitHub (Jun 4, 2016):

Also, doctrine/orm 2.3.x is unmaintained: please upgrade

@Ocramius commented on GitHub (Jun 4, 2016): Also, `doctrine/orm` 2.3.x is unmaintained: please upgrade
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5139