[DDC-790] Generating entities with cli failed on inheritated entities due missing PK Created: 06/Sep/10  Updated: 16/Sep/10  Resolved: 15/Sep/10

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.0-BETA4
Fix Version/s: 2.0-BETA4
Security Level: All

Type: Bug Priority: Major
Reporter: Eduard Kracmar Assignee: Jonathan H. Wage
Resolution: Fixed Votes: 0
Labels: None
Environment:

Kubuntu lucid lynx



 Description   

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



 Comments   
Comment by Benjamin Eberlei [ 08/Sep/10 ]

You cannot generate entities in an inheritance hierachy currently

Comment by Benjamin Eberlei [ 15/Sep/10 ]

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?

Comment by Jonathan H. Wage [ 15/Sep/10 ]

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?

Comment by Jonathan H. Wage [ 15/Sep/10 ]

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.

Comment by Eduard Kracmar [ 16/Sep/10 ]

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.

Generated at Sat Nov 22 14:29:01 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.