Doctrine [Semantical Error] Error: Class xxx has no field or association named yyy

For last few days I'm experiencing following issue with doctrine - since I am not allowed to paste any source code, I'll try to describe briefly:

I am using doctrine orm and I need to add a new column to an existing table in DB - mapping between DB and entities is done via xml mapping file - here are the steps I've proceeded:

  1. I've added into the entity file - let's call it Entity.php - new field for that newColumn
  2. I've added info about this newColumn into the XML mapping file as new XML element 'field'
  3. I've executed doctrine command to change the schema of the DB based on edited mapping file
  4. I've updated the query in EntityRepository.php file to include this new column.

When I then run the application, I am still getting this error:

 [Semantical Error] Error: Class Entity.php has no field or association named newColumn

So, if I am understanding this properly, it is saying that in the Entity.php is not field newColumn to which should be the new DB column mapped.

But that is not the case, since it was the very first step I've done.

I've already tried this:

  1. Checked there is no typo in name of the newColumn across all files
  2. Checked the field in Entity.php has proper access modifiers - i.e. it is not private
  3. Cache was cleared for the case that some bad version of Entity.php was stored
  4. I've restarted apache server which the application runs on

Solution 1:

Check your metadata cache. If you're using some external caching mechanism (like Memcached or xcache) it's probably shared across your vhosts. If one vhost populates the cache with its own mapping metadata (after apache restart), second vhost just uses it and doesn't care about different .dcm.xml mappings.

If it's your development server/vhost, it's usually much better to disable ORM caching at all (config/autoload/database.local.php).

Solution 2:

Maybe my problem and solution would help somebody.

/* * 
* @ORM\Column(name="user_id")  
*/ 
protected $userId;

No, there was no typo in variable name. Access is correct and everything looked to be fine. Some of you probably already see the problem. Yes. It's /* * instead of /**. I took me about hour to find it :] What was strange - it was working in join, but not when I have used it in where.

Solution 3:

Have the same problem. The solution was to replace in query condition like

LOWER(l.bank_title) LIKE :search

with its camelCase variant:

LOWER(l.bankTitle) LIKE :search