Affects Version/s: 2.1.1
Fix Version/s: None
Security Level: All
Environment:Debian Linux 6.0, MySQL Server 5.0.51a
For entities that are instances of an entity class that inherits from another entity class, querying them directly using DQL will generate a broken SQL statement in which a table alias is referenced but never declared.
Here is an example SQL query:
SELECT a from \A a where a.someField = 1
Assume that A is an entity class that inherits from another entity class, say B.
The generated query will then be of the following (wrong) form:
SELECT i0_.someField as someField0, a1_.someOtherfield AS someOtherfield1 FROM A a1_ WHERE a1_.someField = 1 LIMIT 1
You can see that the generated query references two table aliases in the select list (i0_ and a1_), but only declares one (a1_). This can't possibly work. Apparently the inheritance join does not make it into SQL. As inheritance joins are documented to happen transparently, I believe this is unintended behaviour.
The error message is then, of course, something like this:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'i0_.somefield' in 'field list'' ...
Strangely, it also happens for fields that are replicated to the subclass, e. g. the primary key.
Querying entity classes that do not inherit from other entity classes works as expected though, including the base classes in an entity inheritance hierarchy.