Class inheritance without adding a new field breaks find (wrong SQL generated) #7097

Closed
opened 2026-01-22 15:44:37 +01:00 by admin · 2 comments
Owner

Originally created by @nunoplopes on GitHub (Jan 25, 2023).

Bug Report

Q A
BC Break ?
Version 2.14.1

Summary

I have an abstract class with 1 field. An inherited class adds no extra fields.
Doing a repository find of the inherited class generates wrong SQL.

Current behavior

Throws an exception (Uncaught PDOException: SQLSTATE[HY000]: General error: 1 no such column: t0.name in Connection.php:60) due to broken SQL that is generated.
The generated SQL is:

SELECT t1.name AS name_2 FROM GitHubRepository t1 WHERE t0.name = ?

The code looks like:

/** @Entity */
abstract class Repository {
  /** @Id @Column(length=255) */
  public string $name;
}

/** @Entity */
class GitHubRepository extends \Repository {
  // no fields
}

// exception here:
$entityManager->find('GitHubRepository', $id);

In terms of tables, the table GitHubRepository has 1 column (name), and table Repository has no columns.

Originally created by @nunoplopes on GitHub (Jan 25, 2023). ### Bug Report | Q | A |------------ | ------ | BC Break | ? | Version | 2.14.1 #### Summary I have an abstract class with 1 field. An inherited class adds no extra fields. Doing a repository find of the inherited class generates wrong SQL. #### Current behavior Throws an exception (`Uncaught PDOException: SQLSTATE[HY000]: General error: 1 no such column: t0.name in Connection.php:60`) due to broken SQL that is generated. The generated SQL is: ```sql SELECT t1.name AS name_2 FROM GitHubRepository t1 WHERE t0.name = ? ``` The code looks like: ```php /** @Entity */ abstract class Repository { /** @Id @Column(length=255) */ public string $name; } /** @Entity */ class GitHubRepository extends \Repository { // no fields } // exception here: $entityManager->find('GitHubRepository', $id); ``` In terms of tables, the table `GitHubRepository` has 1 column (name), and table `Repository` has no columns.
admin closed this issue 2026-01-22 15:44:37 +01:00
Author
Owner

@nunoplopes commented on GitHub (Jan 25, 2023):

Closing. I should be using @MappedSuperclass, not @Entity.

@nunoplopes commented on GitHub (Jan 25, 2023): Closing. I should be using `@MappedSuperclass`, not `@Entity`.
Author
Owner

@mpdude commented on GitHub (Jan 26, 2023):

I think that with #10431 (which is in the current 2.15.x-dev), you should have been given a deprecation notice for a missing inheritance declaration, and in 3.0, it would have been a failure.

@mpdude commented on GitHub (Jan 26, 2023): I think that with #10431 (which is in the current `2.15.x-dev`), you should have been given a deprecation notice for a missing inheritance declaration, and in 3.0, it would have been a failure.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7097