Entity extending embeddable: Duplicate definition of column 'colName' on entity 'Foo' in a field or discriminator column mapping. #6435

Closed
opened 2026-01-22 15:33:14 +01:00 by admin · 4 comments
Owner

Originally created by @marhub on GitHub (Mar 25, 2020).

Originally assigned to: @malarzm on GitHub.

BC Break Report

Q A
BC Break yes
Version 2.7.2

Summary

code below stopped working after update from 2.7.0 to 2.7.2.
Downgrading fixes issue.

/**
 * @ORM\Embeddable()
 */
class Money
{
    /**
     * @ORM\Column(type = "integer")
     */
    protected $value = 0;
}

/**
 * @ORM\Entity
 */
class Price extends Money
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $priceId;
}

Previous behavior

That code was working in 2.7.0

Current behavior

Schema validation fails with

Duplicate definition of column 'value' on entity 'Price' in a field or discriminator column mapping.

Originally created by @marhub on GitHub (Mar 25, 2020). Originally assigned to: @malarzm on GitHub. ### BC Break Report | Q | A |------------ | ------ | BC Break | yes | Version | 2.7.2 #### Summary code below stopped working after update from 2.7.0 to 2.7.2. Downgrading fixes issue. <pre>/** * @ORM\Embeddable() */ class Money { /** * @ORM\Column(type = "integer") */ protected $value = 0; } /** * @ORM\Entity */ class Price extends Money { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $priceId; }</pre> #### Previous behavior That code was working in 2.7.0 #### Current behavior Schema validation fails with > Duplicate definition of column 'value' on entity 'Price' in a field or discriminator column mapping.
admin closed this issue 2026-01-22 15:33:14 +01:00
Author
Owner

@SenseException commented on GitHub (Mar 26, 2020):

Why do you extend the embeddable class in your example?

@SenseException commented on GitHub (Mar 26, 2020): Why do you extend the [embeddable](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/tutorials/embeddables.html#separating-concerns-using-embeddables) class in your example?
Author
Owner

@malarzm commented on GitHub (May 7, 2020):

@marhub I'm sorry to say, but an Entity extending Embeddable is not correct mapping. We will improve the schema validation to let users know about it. I believe the correct approach in your case is Price having a Money field:

/**
 * @ORM\Entity
 */
class Price
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $priceId;
    
    /**
     * @ORM\Embedded(class=Money::class)
     */
    private $money;
}

The other (and less feasible in my opinion) approach would be to have Money mapped as a @ORM\MappedSuperclass and have two separate classes: MoneyEmbedded extends Money and Price extends Money - that mapping would be correct from ORM's point of view.

@malarzm commented on GitHub (May 7, 2020): @marhub I'm sorry to say, but an Entity extending Embeddable is not correct mapping. We will improve the schema validation to let users know about it. I believe the correct approach in your case is `Price` having a `Money` field: ``` /** * @ORM\Entity */ class Price { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $priceId; /** * @ORM\Embedded(class=Money::class) */ private $money; } ``` The other (and less feasible in my opinion) approach would be to have `Money` mapped as a `@ORM\MappedSuperclass` and have two separate classes: `MoneyEmbedded extends Money` and `Price extends Money` - that mapping would be correct from ORM's point of view.
Author
Owner

@marhub commented on GitHub (May 26, 2020):

OK, but there is no information about Embeds not extending Entities in documentation, is it ?
So seems like this "bug fix" will be BC break for many people like me. For now we have to stick to doctrine 2.7.0 :(

@marhub commented on GitHub (May 26, 2020): OK, but there is no information about Embeds not extending Entities in documentation, is it ? So seems like this "bug fix" will be BC break for many people like me. For now we have to stick to doctrine 2.7.0 :(
Author
Owner

@beberlei commented on GitHub (May 26, 2020):

@marhub we have reverted the commits in 2.7.1 and 2.7.2 related to embeddables, however we will start throwing Schema Validator errors for this use-case and remove it in the future. So you can prepare yourself to fix the mapping. Entities cannot extend Embeddables. Instead you can have a MappedSuperclass and extend it from both the Entity and the Embeddable.

@beberlei commented on GitHub (May 26, 2020): @marhub we have reverted the commits in 2.7.1 and 2.7.2 related to embeddables, however we will start throwing Schema Validator errors for this use-case and remove it in the future. So you can prepare yourself to fix the mapping. Entities *cannot* extend Embeddables. Instead you can have a MappedSuperclass and extend it from both the Entity and the Embeddable.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6435