DDC-1212: Exception of mapping of ID generation strategy #1524

Closed
opened 2026-01-22 13:16:55 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 16, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user comfortablynumb:

Hi all,

After updating today Doctrine 2 from master branch I'm getting:

Entity of type "Entity" is missing an assigned ID. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly.

Was there a change on the mapping of ID generation strategy? I was using a commit of the master branch from 1 o 2 weeks ago and it was working ok. I took a look at the repo for changes on the last days but I couldn't find anything related to this.

I paste the mapping and entities here:

Element:

/****
 * @ORM\MappedSuperclass
 */
abstract class Element
{
    /****
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;
}

File:

/****
 * @ORM\Entity
 * @ORM\Table(name="file")
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="discriminator", type="string")
 * @ORM\DiscriminatorMap({
        "image"  = "Image",
    })
 */
abstract class File extends Element
{
     // Fields
}

And Image:

/****
 * @ORM\Entity
 * @ORM\Table(name="image")
 */
class Image extends File
{
     // Fields
}

Thanks in advance!

Originally created by @doctrinebot on GitHub (Jun 16, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user comfortablynumb: Hi all, After updating today Doctrine 2 from master branch I'm getting: Entity of type "Entity" is missing an assigned ID. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly. Was there a change on the mapping of ID generation strategy? I was using a commit of the master branch from 1 o 2 weeks ago and it was working ok. I took a look at the repo for changes on the last days but I couldn't find anything related to this. I paste the mapping and entities here: Element: ``` /**** * @ORM\MappedSuperclass */ abstract class Element { /**** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="IDENTITY") */ protected $id; } ``` File: ``` /**** * @ORM\Entity * @ORM\Table(name="file") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="discriminator", type="string") * @ORM\DiscriminatorMap({ "image" = "Image", }) */ abstract class File extends Element { // Fields } ``` And Image: ``` /**** * @ORM\Entity * @ORM\Table(name="image") */ class Image extends File { // Fields } ``` Thanks in advance!
admin added the Bug label 2026-01-22 13:16:55 +01:00
admin closed this issue 2026-01-22 13:16:55 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 16, 2011):

Comment created by @beberlei:

Do you "use" the mapping AS ORM namespace?

@doctrinebot commented on GitHub (Jun 16, 2011): Comment created by @beberlei: Do you "use" the mapping AS ORM namespace?
Author
Owner

@doctrinebot commented on GitHub (Jun 16, 2011):

Comment created by comfortablynumb:

Yes, sorry for not including that. I had to add this to my entities 1 o 2 weeks ago when I updated all my vendors:

use Doctrine\ORM\Mapping as ORM;

Is it still right?

@doctrinebot commented on GitHub (Jun 16, 2011): Comment created by comfortablynumb: Yes, sorry for not including that. I had to add this to my entities 1 o 2 weeks ago when I updated all my vendors: use Doctrine\ORM\Mapping as ORM; Is it still right?
Author
Owner

@doctrinebot commented on GitHub (Jun 16, 2011):

Comment created by @beberlei:

Fixed

@doctrinebot commented on GitHub (Jun 16, 2011): Comment created by @beberlei: Fixed
Author
Owner

@doctrinebot commented on GitHub (Jun 16, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jun 16, 2011): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Jun 16, 2011):

Comment created by comfortablynumb:

Great!

I want to say just in case BTW that removing the mapped superclass and moving all its fields to, for example, "File" makes the error go away.

Thanks a lot!

@doctrinebot commented on GitHub (Jun 16, 2011): Comment created by comfortablynumb: Great! I want to say just in case BTW that removing the mapped superclass and moving all its fields to, for example, "File" makes the error go away. Thanks a lot!
Author
Owner

@carlosscesarr commented on GitHub (Jan 25, 2024):

Qual foi a solução?

@carlosscesarr commented on GitHub (Jan 25, 2024): Qual foi a solução?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1524