26

I'm trying to add Doctrine on top of an existing database. I let Doctrine generate annotated entities and adjusted from there. When I try to load the entity below I get the error PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Property Users\\User::$resellerID does not exist'

class User
{
    /* ... */

    /**
     * @var \Doctrine\Common\Collections\Collection
     *
     * @ORM\ManyToOne(targetEntity="\Resellers\Reseller")
     * @ORM\JoinTable(name="reseller",
     *   joinColumns={
     *     @ORM\JoinColumn(name="resellerID", referencedColumnName="resellerID")
     *   },
     *   inverseJoinColumns={
     *     @ORM\JoinColumn(name="resellerID", referencedColumnName="resellerID")
     *   }
     * )
     */
    private $reseller;

    /* ... */
}

Both the user and reseller tables have resellerID columns. My understanding is that for joining ID columns you don't add the ID columns as properties in the entity class. So what's causing the ReflectionException?

Matt S
  • 14,976
  • 6
  • 57
  • 76

7 Answers7

66

Since I had renamed the autogenerated property from resellerID to reseller (after trying to use it) it turns out I needed to clear the Doctrine cache.

php vendor/bin/doctrine.php orm:clear-cache:result
php vendor/bin/doctrine.php orm:clear-cache:query
php vendor/bin/doctrine.php orm:clear-cache:metadata

Or, if you are using Symfony with Doctrine:

php bin/console doctrine:cache:clear-result
php bin/console doctrine:cache:clear-query
php bin/console doctrine:cache:clear-metadata
mc.watras
  • 381
  • 3
  • 10
Matt S
  • 14,976
  • 6
  • 57
  • 76
  • What if none of the given answers works ? I 've using Symfony since 2014 and never had such issue until I start to use 'json' and 'json_array' types in an entity . – Diego Favero May 30 '19 at 14:39
  • 1
    @DiegoFavero I would open a new question specific to your scenario. Link back to this one so you don't get flagged as a duplicate. I've never used those types in an entity so maybe there's something special that needs to be done. – Matt S May 30 '19 at 17:38
  • Paid a bit of research, and I think I will open an issue ticket on Doctrine's page because I did not find any similar problem ! – Diego Favero May 30 '19 at 20:40
  • to run all these commands with the same order in the answer is really important btw. – LugiHaue Apr 15 '20 at 14:54
3

For me clearing the PHP APC cache was the solution

<?php
apc_clear_cache();
Community
  • 1
  • 1
michalzuber
  • 5,079
  • 2
  • 28
  • 29
  • This was what I needed in the end - clearing the doctrine cache turned out to be a temporary measure and it was only when I restarted memcached that I got rid of the error for good. – beterthanlife Jul 13 '17 at 09:22
  • Same idea if using opcache with the opcache.validate_timestamps = false flag. Clear the cache by restarting the web server. Thanks @michalzuber for the idea! – lucian303 Feb 28 '19 at 01:07
1

Anyway, it helped me

php artisan  doctrine:clear:metadata:cache
0

Usually on production you want something like this:

php bin/console doctrine:cache:clear-result --env=prod
php bin/console doctrine:cache:clear-query --env=prod
php bin/console doctrine:cache:clear-metadata --env=prod
Jeffrey L. Roberts
  • 2,844
  • 5
  • 34
  • 69
mariano
  • 84
  • 3
0

My error still occurred when I attempted to clear the doctrine cache.

What worked for me was to manually clear the cache by deleting the folder under /storage/framework/cache/*

TwistedSt
  • 632
  • 1
  • 6
  • 14
0

In Symfony, due to Docker container permissions, I had to manually delete everything under /var/cache/.

user13859151
  • 113
  • 6
0

If anyone is reading this while using a Docker container:

  1. Use Terminal within your PHP/Symfony container.
  2. Enter the doctrine cache clear commands referenced in older answers:
    php bin/console doctrine:cache:clear-result
    php bin/console doctrine:cache:clear-query
    php bin/console doctrine:cache:clear-metadata
  1. Do the APC cache clear also referenced in older answers:
    php -r "apc_clear_cache();"
  1. Restart your PHP / Symfony container in Docker.

The restart as a last step ends up clearing whatever is lingering, at least in my case. Hope this helps anyone else using Docker.

CMG
  • 117
  • 6