superclass for JPA1 Entities
  • bloo November 2011

    I want all of my JPA1 @Entity classes to contain "@Id Long id" and "@Version int version" properties (with setters and getters) and I could either have those generated with the plugin, or exist in a @MappedSuperclass and all @Entity classes extend.

    Which option would be considered the "best practice" when diagraming these objects in the class diagram - and how would I best go about making these customizations?

  • Manuel Bork November 2011

    Hi Bloo,

    I'd prefer the second approach. Just create both properties in the common superclass and let the entities extend it.

    If this is not an option (e.g. because you'd like to extend another class), you can create an own code style and add both properties into the "additionalMember" template. Have a look at the tutorial "creating code styles for existing code" (http://www.uml-lab.com/en/uml-lab/tutorials/codestyles-tutorial/) for that purpose. But I'd then create an interface containing both properties and let the entities implement it.

    Best regards
    Manuel

  • bloo November 2011

    Hi Manuel,

    Is there a way to automatically have all @Entity classes extend this @MappedSuperclass? I have a lot of classes in my diagram and want all of the JPA entities to have the @Id and @Version attributes that this superclass contains without having to manually "extend" each one in the diagram. Do I need to create a new Stereotype or something?

  • Manuel Bork November 2011

    Hi Bloo,

    well, you can create an own code style which automatically adds the generalization to your super class in the code. For that purpose redefine the template "File::classifier". It's important to keep the checkbox "copy selected template body" checked. Add your code for the generalization after the class declaration.

    But that's not the approach which I would choose. I'd prefer to model the generalization explicitely, because I think the model should reflect this design decision. This should not take much time, just drag'n'drop from the entities to your @MappedSuperclass.

  • bloo November 2011

    You've convinced me - I agree with your point. Done and done!

Welcome!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion