2.6. Add an Entity Using Hibernate Tools
A new entity class can be added to the TicketMonster project using Hibernate Tools. In the procedure below a
Venue entity class is created to hold information about the venues where events will be held. This Venue entity has id, name, description and capacity fields.
Procedure 2.6. Add an Entity Using Hibernate Tools
- In the Project Explorer view, expand ticket-monster→Java Resources→src/main/java.
- Right-click org.jboss.jdf.example.ticketmonster.model and click →.
- In the Name field, type
Venueand click . This creates aVenue.javafile that is automatically opened in a Java editor.
Figure 2.9. New
VenueClass using Java Class Wizard - Add fields to the entity by adding the following lines in between the braces of the
Venueclassprivate Long id; private String name; private String description; private int capacity; - Save the
Venue.javafile by pressing Ctrl+S (Cmd+S). - Add
getandsetmethods by right-clicking on a new line afterprivate int capacity;and clicking →. - Click and click .
Figure 2.10. List of Attributes Selected for Creating Get and Set Methods
- Save the
Venue.javafile. - Make the class an entity by right-clicking anywhere in the
Venueclass and clicking →. - Ensure org.jboss.jdf.example.ticketmonster.model.Venue is selected and click .
Figure 2.11.
VenueClass Selected for Adding JPA Annotations - Click and save the
Venue.javafile.