How to Create a Java EE 6 Application with JSF 2, EJB 3.1, JPA, and NetBeans IDE 6.8
Creating the Enterprise Application Project
The approach for developing the demo app, CustomerApp, will be from the back end, i.e., the artifacts and services needed by the front-end UI will be created first, then working forward to the User Interface, i.e., the Ajax-based Web UI will be done last.
The first step in creating the application is to create the necessary projects in NetBeans IDE.
- Choose "File > New Project" to open the New Project Wizard. Under Categories, select Java EE; under Projects select Enterprise Application. Click Next.
- Select the project location and name the project, CustomerApp, and click Next.
- Select the installed Glassfish v3 as the server, and Java EE 6 as the Java EE Version, and click Finish.
NetBeans IDE will create 3 projects, namely CustomerApp (Enterprise Application project), CustomerApp-ejb (EJB project), and CustomerApp-war (Web project).
Creating the Entity Classes from the Database
Before anything else, we first need to create the Entity Classes and because in this demo, the Session Beans are responsible for manipulating the data, they will be created in the EJB project.
- In the Projects window, right-click on the CustomerApp-ejb project and select "New > Entity Classes from Database..."
- Select Data Source (Radio button) and in the corresponding dropdown list, select "New Data Source..."
- Specify the JNDI name to be "jdbc/sample", and select "jdbc:derby://localhost:1527/sample [app on APP]" as the Database Connection and click OK.
- Under the Available Tables list box, select CUSTOMER and click on Add button so that it appears in the Selected Tables list box (Note that the related table, DISCOUNT_CODE is also added automatically) and click Next
- Click on the "Create Persistence Unit..." button, select "jdbc/sample" as the Data Source; leave the rest as default and click Create:
- Provide a package name, e.g. "com.customerapp.entity" in the Package field and click Next.
- Change the Collection Type to "java.util.List" and click Finish.
- Take note of the new classes created under the Source Packages in the Projects window:
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)