Fetch EAGER with second_level_cache ON ManyToOne association BUG. #5106

Closed
opened 2026-01-22 14:58:26 +01:00 by admin · 1 comment
Owner

Originally created by @BourotBenjamin on GitHub (Apr 19, 2016).

Originally assigned to: @lcobucci on GitHub.

I get
[request] Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Catchable Fatal Error: Object of class Doctrine\ORM\Cache\AssociationCacheEntry could not be converted to string" at /var/www/Youmiam/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2676
When I try to get an object for the first time, but it only happens when I get an object with an EAGER association and the problem appears when I installed the second level cache.

If it could help, there is my code :
Association :

     /**
     * @ORM\ManyToOne(targetEntity="Acme\MyBundle\Entity\Product", inversedBy="quantities", fetch="EAGER")
     * @ORM\JoinColumn(name="product")
     * @ORM\Cache(usage="NONSTRICT_READ_WRITE")
     */
     private $product;

On the top of this class :
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="region_quantity"))

On the top of the other class :
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="region_product"))

My config :

snc_redis:
    # configure predis as client
    clients:
        doctrine:
            type: predis
            alias: cache_client
            dsn: redis://127.0.0.1
    # configure doctrine caching
    doctrine:
        metadata_cache:
            client: cache
            entity_manager: default
            document_manager: default
        result_cache:
            client: cache
            entity_manager: default
            document_manager: default
            namespace: "dcrc:"
        query_cache:
            client: cache
            entity_manager: default

services:
    snc_second_level_cache:
        class: %snc_redis.doctrine_cache.class%
        calls:
            - ["setRedis", ["@snc_redis.cache_client"]]
            - ["setNamespace", ["DoctrineSecondLevelCache"]] 

doctrine:
    orm:
        entity_managers:
            default:
                metadata_cache_driver: redis
                query_cache_driver: redis
                result_cache_driver: redis
                second_level_cache:
                        region_cache_driver:
                             type: service
                             id: snc_second_level_cache
                        region_lock_lifetime: 60
                        log_enabled: true
                        region_lifetime: 3000
                        enabled: true
                        regions:
                            region_product:
                                lifetime: 3000
                                cache_driver:
                                    type: service
                                    id: snc_second_level_cache
                            region_quantity:
                                lifetime: 3000
                                cache_driver:
                                    type: service
                                    id: snc_second_level_cache`

Thanks in advance.

Originally created by @BourotBenjamin on GitHub (Apr 19, 2016). Originally assigned to: @lcobucci on GitHub. I get `[request] Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Catchable Fatal Error: Object of class Doctrine\ORM\Cache\AssociationCacheEntry could not be converted to string" at /var/www/Youmiam/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2676` When I try to get an object for the first time, but it only happens when I get an object with an EAGER association and the problem appears when I installed the second level cache. If it could help, there is my code : Association : ``` php /** * @ORM\ManyToOne(targetEntity="Acme\MyBundle\Entity\Product", inversedBy="quantities", fetch="EAGER") * @ORM\JoinColumn(name="product") * @ORM\Cache(usage="NONSTRICT_READ_WRITE") */ private $product; ``` On the top of this class : `* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="region_quantity"))` On the top of the other class : `* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="region_product"))` My config : ``` yml snc_redis: # configure predis as client clients: doctrine: type: predis alias: cache_client dsn: redis://127.0.0.1 # configure doctrine caching doctrine: metadata_cache: client: cache entity_manager: default document_manager: default result_cache: client: cache entity_manager: default document_manager: default namespace: "dcrc:" query_cache: client: cache entity_manager: default services: snc_second_level_cache: class: %snc_redis.doctrine_cache.class% calls: - ["setRedis", ["@snc_redis.cache_client"]] - ["setNamespace", ["DoctrineSecondLevelCache"]] doctrine: orm: entity_managers: default: metadata_cache_driver: redis query_cache_driver: redis result_cache_driver: redis second_level_cache: region_cache_driver: type: service id: snc_second_level_cache region_lock_lifetime: 60 log_enabled: true region_lifetime: 3000 enabled: true regions: region_product: lifetime: 3000 cache_driver: type: service id: snc_second_level_cache region_quantity: lifetime: 3000 cache_driver: type: service id: snc_second_level_cache` ``` Thanks in advance.
admin added the Duplicate label 2026-01-22 14:58:26 +01:00
admin closed this issue 2026-01-22 14:58:26 +01:00
Author
Owner

@lcobucci commented on GitHub (Jan 19, 2017):

@BourotBenjamin looks like this is a duplicate of #5578 and as mentioned there we weren't able to reproduce it on the latest version of master.

So I'm closing this issue.

@lcobucci commented on GitHub (Jan 19, 2017): @BourotBenjamin looks like this is a duplicate of #5578 and as mentioned there we weren't able to reproduce it on the latest version of `master`. So I'm closing this issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5106