Annotations 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:
- Right click on the association role (which eventually will become an attribute) and select Owned By > target class.
- An attribute will then being visible on the target class. Right click on the attribute and select Open Specification.
- Click on the small triangle icon at the top right of the specification dialog to bring up the Java Annotations.
- Press the Add button at the bottom of the Java Annotation tab to insert a new annotation.
- Specify the Name of the annotation. You can also specify the value of the annotation by pressing Add button inside the Add Annotation.
- Press OK to close the Add Annotation dialog, and press OK again to close the attribute specification dialog.
- Now go to Tools > Hibernate > Generate Code…
- Make sure selecting JPA in the Framework field of the Database Code Generation dialog, and press OK to proceed the code generation.
Now the custom annotations are being generated into hibernate code.