DDC-790: Generating entities with cli failed on inheritated entities due missing PK #972

Closed
opened 2026-01-22 12:57:47 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 6, 2010).

Originally assigned to: @jwage on GitHub.

Jira issue originally created by user edke:

While generating entities with:

./doctrine orm:generate-entities --generate-methods=true ../tmp/entities

getting MappingException: No identifier/primary key specified for Entity 'Entities\Admin'. Every Entity must have an identifier/primary key.

Admin is class inheritated, definition included:

Person: http://pastebin.com/5r9fXrAu
Admin: http://pastebin.com/51BcRZWZ

Originally created by @doctrinebot on GitHub (Sep 6, 2010). Originally assigned to: @jwage on GitHub. Jira issue originally created by user edke: While generating entities with: ./doctrine orm:generate-entities --generate-methods=true ../tmp/entities getting MappingException: No identifier/primary key specified for Entity 'Entities\Admin'. Every Entity must have an identifier/primary key. Admin is class inheritated, definition included: Person: http://pastebin.com/5r9fXrAu Admin: http://pastebin.com/51BcRZWZ
admin added the Bug label 2026-01-22 12:57:47 +01:00
admin closed this issue 2026-01-22 12:57:48 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 8, 2010):

Comment created by @beberlei:

You cannot generate entities in an inheritance hierachy currently

@doctrinebot commented on GitHub (Sep 8, 2010): Comment created by @beberlei: You cannot generate entities in an inheritance hierachy currently
Author
Owner

@doctrinebot commented on GitHub (Sep 15, 2010):

Comment created by @beberlei:

AFter having looked at the mappings, how do you plan to generate methods from annotated entities? I think the entity generator won't allow that, jwage?

@doctrinebot commented on GitHub (Sep 15, 2010): Comment created by @beberlei: AFter having looked at the mappings, how do you plan to generate methods from annotated entities? I think the entity generator won't allow that, jwage?
Author
Owner

@doctrinebot commented on GitHub (Sep 15, 2010):

Comment created by @jwage:

The problem with everything is that the inheritance hierarchy is not mapped, instead it is read at runtime from the classes themselves. So, when you're generating the initial entities from the mapping information, you don't have that information, so we can't properly generate a class with the "class ClassName extends SomeOtherClass" because we simply don't know it.

To work around it all you have to do is manually create the file with the empty class inside of it, extending the class you want. When you run the orm:generate-entities again, it can properly read the subclasses of every entity and the generation will update the classes existing classes properties and methods instead of trying to generate a new class.

Does that clear things up? I think the only way to fix it would be to allow the user to manually specify the all the inheritance information in the mapping information instead of reading it at run-time. That way we have all the information about some entities even before the actual classes exist and we can generate the right code then.

Thoughts?

@doctrinebot commented on GitHub (Sep 15, 2010): Comment created by @jwage: The problem with everything is that the inheritance hierarchy is not mapped, instead it is read at runtime from the classes themselves. So, when you're generating the initial entities from the mapping information, you don't have that information, so we can't properly generate a class with the "class ClassName extends SomeOtherClass" because we simply don't know it. To work around it all you have to do is manually create the file with the empty class inside of it, extending the class you want. When you run the orm:generate-entities again, it can properly read the subclasses of every entity and the generation will update the classes existing classes properties and methods instead of trying to generate a new class. Does that clear things up? I think the only way to fix it would be to allow the user to manually specify the all the inheritance information in the mapping information instead of reading it at run-time. That way we have all the information about some entities even before the actual classes exist and we can generate the right code then. Thoughts?
Author
Owner

@doctrinebot commented on GitHub (Sep 15, 2010):

Comment created by @jwage:

Benjamin, yes it is possible. But like I mentioned above we don't know what class an entity extends until the class is created. You have no way to say in the mapping information that this entity extends this class.

If you have an entity already created with just the annotated properties, and you run the command to generate entities it will update the class adding the methods to the class. If you were to add a new property to the class and annotate and run the command again, it would only add the 2 new methods to the bottom of the class.

@doctrinebot commented on GitHub (Sep 15, 2010): Comment created by @jwage: Benjamin, yes it is possible. But like I mentioned above we don't know what class an entity extends until the class is created. You have no way to say in the mapping information that this entity extends this class. If you have an entity already created with just the annotated properties, and you run the command to generate entities it will update the class adding the methods to the class. If you were to add a new property to the class and annotate and run the command again, it would only add the 2 new methods to the bottom of the class.
Author
Owner

@doctrinebot commented on GitHub (Sep 15, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Sep 15, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Sep 16, 2010):

Comment created by edke:

This is really what I'm looking for. I create classes, fill them with properties and define annotations for them. Then I run cli tool to generate all methods (getters and setters) for classes to skip the boring part of creating entity. Then if required, I modify getters and setters.

Only problem was that it failed on classes that were inheritated because they were missing primary keys.

As a workaround while generating methods for new entities, I moved away from project inheritated entities and after generating I moved them back.

@doctrinebot commented on GitHub (Sep 16, 2010): Comment created by edke: This is really what I'm looking for. I create classes, fill them with properties and define annotations for them. Then I run cli tool to generate all methods (getters and setters) for classes to skip the boring part of creating entity. Then if required, I modify getters and setters. Only problem was that it failed on classes that were inheritated because they were missing primary keys. As a workaround while generating methods for new entities, I moved away from project inheritated entities and after generating I moved them back.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#972