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

  1. In the Project Explorer view, expand ticket-monsterJava Resourcessrc/main/java.
  2. Click org.jboss.jdf.example.ticketmonster.model and press Ctrl+4 (Cmd+4).
  3. From the Forge wizards list, click JPA: New Entity.
  4. In the Entity name field, type Event and click Finish.
    Create an Event Entity with the Forge 2 JPA: New Entity Wizard

    Figure 2.7. New Event Entity using Forge 2 JPA: New Entity Wizard

  5. In the Project Explorer view, ensure org.jboss.jdf.example.ticketmonsterEvent.java is selected and press Ctrl+4.
  6. From the Forge wizards list, click JPA: New Field.
  7. Complete the fields about the field as follows:
    • In the Field name field, type name.
    • In the Length field, type 50.
    Create a name Field with the Forge 2 JPA: New Field Wizard

    Figure 2.8. New name Field using Forge 2 JPA: New Field Wizard

  8. Click Finish to create the field.
  9. Repeat steps 5 and 6 to create three more fields for the Event entity as follows:
    • description, with Field Type String and Length 1000
    • major, with Field Type Boolean
    • picture, with Field Type String
  10. In the Project Explorer view, right-click Event.java and click Show InForge Console.
  11. 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 to NotNull.
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.