Video summary
Lab12 EJB JPA JSF CRUD: with explanation
Main summary
Key takeaways
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
-
Create the database table
- Use NetBeans’ sample JDBC database.
- Create a
Persontable with these fields:id_person: integer primary keyname: varchar, length 50email: varchar, length 50phone: integer
- Add sample rows, ensuring each ID is unique.
-
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.
-
Generate the persistence layer
- In the EJB module, create an entity class from the database table.
- Create a persistence unit and use a
Listcollection type. - Generate a session bean or facade for the entity. Its methods provide operations such as creating, finding, editing, and removing records.
-
Set up the web application
- Add JavaServer Faces to the web module.
- Create a
controllerpackage and a JSF managed bean namedPersonController. - Set its scope to session and inject the person facade.
- Add a method that calls the facade’s
findAlloperation to retrieve records for display. - Add a
Personproperty with getters and setters so JSF forms can bind to it. - Add controller methods for inserting, deleting, and updating records.
-
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.
- Use the main JSF page,
-
Create the insert page
- Create an
insert.xhtmlJSF page with a form bound to the controller’sPersonproperty. - 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.
- Create an
-
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.
-
Create the update page
- Create an
update.xhtmlpage 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.
- Create an
-
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.
Translate summary in another language
Ask questions to this video
Chat for follow-up questions, clarifications, and source-backed answers.