Description
BC Break Report
Q | A |
---|---|
BC Break | yes |
Version | 2.16.0 |
Summary
Persisting an @Entity
which has it's @Id
defined in it's parent (@MappedSuperclass
) with IDENTITY
generator strategy on PostgreSQL platform.
It seems that the breaking change occured in this PR #10455, specifically changes in ClassMetadataFactory
that removed the condtion of $rootEntityFound
for calling inheritIdGeneratorMapping()
Previous behavior
In version 2.15.5
the IdentityGenerator
used to retrieve inserted id came from the Entity itself with $sequenceName
matching the schema. So the value was retrieved from the correct sequence.
Current behavior
Now the IdentityGenerator
used to retrieve inserted id comes from the parent @MappedSuperclass
and $sequenceName
is wrong (name of parent class + sequence suffix) and non-existent in schema, so a PostgreSQL error about relation not existing is thrown.
How to reproduce
E.g. (irrelevant code and domain-specific terminology is ommited):
/**
* @ORM\MappedSuperclass
*/
abstract class AbstractTaskOperatorHistoryRecord
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private ?int $id = null;
}
/**
* @ORM\Entity()
* @ORM\Table(name="foo_bar_task_operator_history")
*/
class FooBarTaskOperatorHistoryRecord extends AbstractTaskOperatorHistoryRecord
{
}
$this->_em->persist(new FooBarTaskOperatorHistoryRecord());
$this->_em->flush();
The PostgreSQL sequence used by id
column in foo_bar_task_operator_history
table is foo_bar_task_operator_history_id_seq
.
The sequence used to retrieve inserted id was foo_bar_task_operator_history_id_seq
before the breaking change. Now it is trying to get the value from abstracttaskoperatorhistoryrecord_id_seq
which obviously does not and should not exist. The error thrown is
PDOException
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "abstracttaskoperatorhistoryrecord_id_seq" does not exist