Create custom annotation on attributes of generated Hibernate code

tomcat-thumbAnnotations in Java allow developers to define additional metadata information into their source code. Those annotation can be used as instructions to the compiler, compile-time instructor and also as the runtime instruction to the Java VM. Visual Paradigm support generate hibernate source code generation using Java Persistence Annotations (JPA) approach. Besides you can also define custom annotations in model and generate them along with your hibernate source code. This article shows you how to define custom annotations for attributes in generated hibernate source code.

To define custom annotation for hibernate code generation:

  1. Right click on the association role (which eventually will become an attribute) and select Owned By > target class.

    Visualize attribute on class by specify the association owned by the class

    Visualize attribute on class by specify the association owned by the class

  2. An attribute will then being visible on the target class. Right click on the attribute and select Open Specification.

    Open specification dialog of the attribute

    Open specification dialog of the attribute

  3. Click on the small triangle icon at the top right of the specification dialog to bring up the Java Annotations.

    Bring up the Java Annotation tab

    Bring up the Java Annotation tab

  4. Press the Add button at the bottom of the Java Annotation tab to insert a new annotation.

    Add new annotation

    Add new annotation

  5. Specify the Name of the annotation. You can also specify the value of the annotation by pressing Add button inside the Add Annotation.

    Define details of the annotation

    Define details of the annotation

  6. Press OK to close the Add Annotation dialog, and press OK again to close the attribute specification dialog.
  7. Now go to Tools > Hibernate > Generate Code…

    Generate hibernate code

    Generate hibernate code

  8. Make sure selecting JPA in the Framework field of the Database Code Generation dialog, and press OK to proceed the code generation.

    Specify JPA as the framework during code generation

    Specify JPA as the framework during code generation

Now the custom annotations are being generated into hibernate code.

Custom annotation in generated code

Custom annotation in generated code

Related Know-how

Related Link

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply