Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-790

Generating entities with cli failed on inheritated entities due missing PK

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA4
    • Fix Version/s: 2.0-BETA4
    • Component/s: ORM
    • Security Level: All
    • 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

        Activity

        Hide
        Benjamin Eberlei added a comment -

        You cannot generate entities in an inheritance hierachy currently

        Show
        Benjamin Eberlei added a comment - You cannot generate entities in an inheritance hierachy currently
        Hide
        Benjamin Eberlei added a comment -

        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?

        Show
        Benjamin Eberlei added a comment - 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?
        Hide
        Jonathan H. Wage added a comment -

        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?

        Show
        Jonathan H. Wage added a comment - 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?
        Hide
        Jonathan H. Wage added a comment -

        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.

        Show
        Jonathan H. Wage added a comment - 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.
        Hide
        Eduard Kracmar added a comment -

        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.

        Show
        Eduard Kracmar added a comment - 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.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Eduard Kracmar
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: