Search

2.6. Add an Entity Using Hibernate Tools

download PDF
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

  1. In the Project Explorer view, expand ticket-monsterJava Resourcessrc/main/java.
  2. Right-click org.jboss.jdf.example.ticketmonster.model and click NewClass.
  3. In the Name field, type Venue and click Finish. This creates a Venue.java file that is automatically opened in a Java editor.
    In the Name field, type Venue and click Finish.

    Figure 2.9. New Venue Class using Java Class Wizard

  4. Add fields to the entity by adding the following lines in between the braces of the Venue class
    private Long id;
    private String name;
    private String description;
    private int capacity;
  5. Save the Venue.java file by pressing Ctrl+S (Cmd+S).
  6. Add get and set methods by right-clicking on a new line after private int capacity; and clicking SourceGenerate Getters and Setters.
  7. Click Select All and click OK.
    Click Select All and click OK.

    Figure 2.10. List of Attributes Selected for Creating Get and Set Methods

  8. Save the Venue.java file.
  9. Make the class an entity by right-clicking anywhere in the Venue class and clicking SourceGenerate Hibernate/JPA annotations.
  10. Ensure org.jboss.jdf.example.ticketmonster.model.Venue is selected and click Next.
    Ensure org.jboss.jdf.example.ticketmonster.model.Venue is selected and click Next.

    Figure 2.11. Venue Class Selected for Adding JPA Annotations

  11. Click Finish and save the Venue.java file.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.