Video summary

Lab12 EJB JPA JSF CRUD: with explanation

Main summary

Key takeaways

Educational

Summary

The video demonstrates how to build a Java EE employee information application using EJB, JPA, and JSF. The application supports the four CRUD operations—create, read, update, and delete—on a database table.

Main Concepts

  • JPA maps the database table to a Java entity.
  • EJB provides database operations through a generated facade.
  • JSF supplies the web pages and form controls.
  • A session-scoped managed bean connects the JSF pages to the EJB layer and handles user actions.

Method and Project Structure

  1. Create the database table

    • Use NetBeans’ sample JDBC database.
    • Create a Person table with these fields:
      • id_person: integer primary key
      • name: varchar, length 50
      • email: varchar, length 50
      • phone: integer
    • Add sample rows, ensuring each ID is unique.
  2. Create the enterprise application

    • In NetBeans, create an Enterprise Application project containing an EJB module and a web module.
    • The demonstration uses GlassFish and Java EE 7.
  3. Generate the persistence layer

    • In the EJB module, create an entity class from the database table.
    • Create a persistence unit and use a List collection type.
    • Generate a session bean or facade for the entity. Its methods provide operations such as creating, finding, editing, and removing records.
  4. Set up the web application

    • Add JavaServer Faces to the web module.
    • Create a controller package and a JSF managed bean named PersonController.
    • Set its scope to session and inject the person facade.
    • Add a method that calls the facade’s findAll operation to retrieve records for display.
    • Add a Person property with getters and setters so JSF forms can bind to it.
    • Add controller methods for inserting, deleting, and updating records.
  5. Build the employee list page

    • Use the main JSF page, index.xhtml, to display a data table populated with database records.
    • Show each person’s ID, name, email, and phone number.
    • Add an Insert record link that navigates to the insert page.
    • Add Delete and Update actions for each row.
    • A border attribute can be used to add a table border.
  6. Create the insert page

    • Create an insert.xhtml JSF page with a form bound to the controller’s Person property.
    • Provide fields for the new record and an Insert button.
    • The button calls the controller’s insert method, which invokes the facade’s create operation and returns to the list page.
  7. Implement deletion

    • Add a delete action to each row, passing that person object to the controller.
    • The controller calls the facade’s remove operation and returns to the list page.
    • The demonstration includes a confirmation prompt with OK and Cancel options.
    • If a JSF command link behaves unreliably, try a command button and check that its markup is correctly closed and quoted.
  8. Create the update page

    • Create an update.xhtml page with a form for editing a record.
    • Do not expose the ID field; the demonstration allows editing the name, email, and phone number.
    • Use an update button to submit changes and return to the list page.
  9. Build and test

    • Clean and build the enterprise application before running it, particularly after making changes.
    • Run the application on the configured server and check that the list displays database records.
    • Test inserting, deleting, and updating records, then verify the changes in the database.

Practical Lessons

  • Use the correct JSF page type and ensure component tags are properly closed.
  • JSF-bound properties need getters and setters to be available to the page.
  • Clean builds can help avoid errors caused by stale or incompletely built project files.
  • The application separates database access, request handling, and presentation across the EJB module, controller, and JSF pages.

Speakers and Sources

  • Speaker: One instructor or narrator throughout, attributed to Thirumurugan Shanmugam based on the channel information.
  • Technologies and tools mentioned: NetBeans, the sample JDBC database, Java EE 7, GlassFish, EJB, JPA, and JSF. No additional speakers or external sources are identified in the subtitles.

Rate this summary

Your feedback will help improve summaries.

Improve this summary

Reprocess with a stronger model when the summary feels incomplete or inaccurate.

Pro

Translate summary in another language

Pro

Ask questions to this video

Chat for follow-up questions, clarifications, and source-backed answers.

Coming soon

Share this summary

Original video