-
Language:
English
-
Language:
English
Red Hat Training
A Red Hat training course is available for Red Hat JBoss Developer Studio
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 New→Class.
- In the Name field, type
Venue
and click Finish. 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 Source→Generate Getters and Setters. - Click Select All and click OK.
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 Source→Generate Hibernate/JPA annotations. - Ensure org.jboss.jdf.example.ticketmonster.model.Venue is selected and click Next.
Figure 2.11.
Venue
Class Selected for Adding JPA Annotations - Click Finish and save the
Venue.java
file.