DDC-2543: EntityManager#getReference returns NULL on JOINED inheritance. #3191

Open
opened 2026-01-22 14:14:53 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 3, 2013).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user naroga:

The following line returns null, when it shouldn't:

    $em->getReference('app:PessoaJuridica', 3);

PessoaJurica inherits from Pessoa. Here goes the mapping.

 /****
 * Pessoa
 *
 * @Table(name="pessoa")
 * @Entity(repositoryClass="Sicneo\Database\Repository\Pessoa")
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="tipo", type="string")
 * @DiscriminatorMap({
 *     "Física" = "PessoaFisica",
 *     "Jurídica" = "PessoaJuridica",
 *     "Internacional" = "PessoaInternacional"
 * })
 * @copyright Copyright (c) 2012 Funarbe Inc. (http://www.funarbe.org.br)
 */
class Pessoa
{
    ...
}
/****
 * PessoaJuridica
 *
 * @Table(name="pessoajuridica")
 * @Entity(repositoryClass="Sicneo\Database\Repository\PessoaJuridica")
 *
 * @copyright Copyright (c) 2012 Funarbe Inc. (http://www.funarbe.org.br)
 */
class PessoaJuridica extends Pessoa
{
    ...
}

The thing is: both 'Pessoa' and 'PessoaJuridica' with ID=3 exist on the database. Pessoa.tipo = "Jurídica". Everything seems to be correctly set up, but getReference keeps returning null.

These are my tables:

mysql> SELECT * FROM pessoa;
|| id || nome || tipo || ativo || dtregistro ||
| 1 | Bruno | Física | 1 | 2013-01-01 00:00:00 |
| 2 | Gestor teste | Jurídica | 1 | 2013-01-01 00:00:00 |
| 3 | Coordenador teste | Jurídica | 1 | 2013-01-01 00:00:00 |
| 4 | Pessoa Internacional | Internacional | 1 | 2013-01-01 00:00:00 |
| 5 | Empresa | Jurídica | 1 | 2013-01-01 00:00:00 |
5 rows in set (0.00 sec)

mysql> SELECT id, cnpj FROM pessoajuridica;
|| id || cnpj ||
| 3 | 33153182000190 |
| 5 | 88302137000141 |
| 2 | 99276220000100 |
3 rows in set (0.00 sec)

More info:
$em->getRepository("app:Pessoa")->find(3); //returns a PessoaJuridica entity, as it should.
and

$em->getRepository("app:PessoaJuridica")->find(3); // returns null. No idea why.

Originally created by @doctrinebot on GitHub (Jul 3, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user naroga: The following line returns null, when it shouldn't: ``` $em->getReference('app:PessoaJuridica', 3); ``` PessoaJurica inherits from Pessoa. Here goes the mapping. ``` /**** * Pessoa * * @Table(name="pessoa") * @Entity(repositoryClass="Sicneo\Database\Repository\Pessoa") * @InheritanceType("JOINED") * @DiscriminatorColumn(name="tipo", type="string") * @DiscriminatorMap({ * "Física" = "PessoaFisica", * "Jurídica" = "PessoaJuridica", * "Internacional" = "PessoaInternacional" * }) * @copyright Copyright (c) 2012 Funarbe Inc. (http://www.funarbe.org.br) */ class Pessoa { ... } ``` ``` /**** * PessoaJuridica * * @Table(name="pessoajuridica") * @Entity(repositoryClass="Sicneo\Database\Repository\PessoaJuridica") * * @copyright Copyright (c) 2012 Funarbe Inc. (http://www.funarbe.org.br) */ class PessoaJuridica extends Pessoa { ... } ``` The thing is: both 'Pessoa' and 'PessoaJuridica' with ID=3 exist on the database. Pessoa.tipo = "Jurídica". Everything seems to be correctly set up, but getReference keeps returning null. These are my tables: mysql> SELECT \* FROM pessoa; || id || nome || tipo || ativo || dtregistro || | 1 | Bruno | Física | 1 | 2013-01-01 00:00:00 | | 2 | Gestor teste | Jurídica | 1 | 2013-01-01 00:00:00 | | 3 | Coordenador teste | Jurídica | 1 | 2013-01-01 00:00:00 | | 4 | Pessoa Internacional | Internacional | 1 | 2013-01-01 00:00:00 | | 5 | Empresa | Jurídica | 1 | 2013-01-01 00:00:00 | 5 rows in set (0.00 sec) mysql> SELECT id, cnpj FROM pessoajuridica; || id || cnpj || | 3 | 33153182000190 | | 5 | 88302137000141 | | 2 | 99276220000100 | 3 rows in set (0.00 sec) More info: `$em->getRepository("app:Pessoa")->find(3); //returns a PessoaJuridica entity, as it should.` and `$em->getRepository("app:PessoaJuridica")->find(3); // returns null. No idea why.`
admin added the Bug label 2026-01-22 14:14:53 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3191