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
Venue
and click . This creates aVenue.java
file that is automatically opened in a Java editor.Figure 2.9. New
Venue
Class using Java Class Wizard - Add fields to the entity by adding the following lines in between the braces of the
Venue
classprivate Long id; private String name; private String description; private int capacity;
- Save the
Venue.java
file by pressing Ctrl+S (Cmd+S). - Add
get
andset
methods by right-clicking on a new line afterprivate int capacity;
and clicking → . - Clickand click .
Figure 2.10. List of Attributes Selected for Creating Get and Set Methods
- Save the
Venue.java
file. - Make the class an entity by right-clicking anywhere in the
Venue
class and clicking → . - Ensure org.jboss.jdf.example.ticketmonster.model.Venue is selected and click .
Figure 2.11.
Venue
Class Selected for Adding JPA Annotations - Clickand save the
Venue.java
file.