2.5. Add an Entity Using Forge Tools
A new entity class can be added to the TicketMonster project using Forge Tools. In the procedure below an
Event
entity class is created to hold information about the events for which users can buy tickets. This Event
entity has id, name, description, major and picture fields.
Procedure 2.5. Add an Entity Using Forge Tools
- In the Project Explorer view, expand ticket-monster→Java Resources→src/main/java.
- Click org.jboss.jdf.example.ticketmonster.model and press Ctrl+4 (Cmd+4).
- From the Forge wizards list, click JPA: New Entity.
- In the Entity name field, type
Event
and click .Figure 2.7. New Event Entity using Forge 2 JPA: New Entity Wizard
- In the Project Explorer view, ensure org.jboss.jdf.example.ticketmonster→Event.java is selected and press Ctrl+4.
- From the Forge wizards list, click JPA: New Field.
- Complete the fields about the field as follows:
- In the Field name field, type
name
. - In the Length field, type
50
.
Figure 2.8. New name Field using Forge 2 JPA: New Field Wizard
- Clickto create the field.
- Repeat steps 5 and 6 to create three more fields for the Event entity as follows:
description
, with Field TypeString
and Length1000
major
, with Field TypeBoolean
picture
, with Field TypeString
- In the Project Explorer view, right-click Event.java and click → .
- In the Forge Console view, on the Forge 2 command line enter
constraint-add --onProperty name
and from the list of options enter the number corresponding toNotNull
.