Create an Entity Diagrams
From Taylor
Contents |
Create Diagram
Now the fun can begin!!!
Right-click on a package such as net.taylor.tutorial.entity and select New Class Diagram.
By default the diagram file will be named the same as the package and should be saved in the model folder.
NOTE: If the editor seems sluggish try minimizing the tree in the navigator. There seems to be an issue with too many icons being created. However, I haven't seen this happen for a long time.
First Entity Bean
Select Entity in the diagram palette and drag it to the canvas to create an Entity Bean and enter the name.
Drill-down in the Model Navigator to see that the class was created and that an Entity stereotype was applied. This stereotype is equivalient to the @Entity annotation.
All applied stereotypes are also displayed in the label of a node <<Entity>>. Also, all available and selected stereotypes can be seen in the Properties View Stereotypes tab. Stereotype specific attributes can be set using the Properties View Stereotype Attributes tab
- Use the Save button to save the model and diagram.
Add Properties
First, lets use a shortcut to create a primary key. Right click on the Ticket entity in the navigator and select Add Primary Key. This will add a property named 'id' of type Long with the @Id and @GeneratedValue stereotypes already applied. It also creates a comment for documentation. Thanks to Robert for donating this feature!
Now lets add 'title' and 'description' properties the good ole fashion way.
Select Property in the diagram palette and drag it to the Entity Bean to create a Property and enter the name of 'title'. The type will default to String. Repeat the same for 'description'.
Now add a property named 'date'. Select the 'date' property in the navigator and use the Properties View to set the Type to Date.
NOTE: For basic types be sure to use the ones provided in the types Profile.
NOTE: Change the type of the description property to types.Text so that a Text Area will be generated in the facelet.
For more information on types see Types to Java and JSF Mapping
Also give creating an Enumeration a try. And add some Literals. Then create a status property on the entity bean with a type of Status.
Important: Don't forget to use the Documentation tab to add documentation to each property. This will be used in the generated documentation. More...
Apply Stereotypes
We need to make the 'title' property required. We can do this by adding a stereotype that will be generated into the code as a java annotation.
Click on the 'title' Property in the navigator and go to the Properties View Stereotypes tab. Select the org.hibernate.validator.NotNull stereotype on the left and press the Add button or double-click on it.
In the Properties View on the Stereotype Attributes tab you can then configure the stereotype if need be. For NotNull lets set the Message displayed on error to 'Title is required.'.
Here is the resulting class diagram:
Utilities
Now lets run some helper utilities to make some bulk changes to the model. Right-click on the net.taylor.tutorial.entity package and select Utilities > JPA and then run:
- Add Temporal Stereotypes and
- Add Enumeration Stereotypes
Find out more about the Utilities Menu here.
Optional: At this point it would be a good idea to skip forward to generating the application and then come back and add more complex features in the next iteration.




