CRUD application in Netbeans used Java Persistence API and default SQL Server 2012 DataSource in GlassFish

What is Java Persistence API? In this post I describe You it step by step in practical project. You must early create database with several tables. I create mine in SQL Server 2012 . My database of test name has tables: person, prof, pp and authors. It is simple diagram these tables with realations:


First you must open Netbeans to add driver of SQL Server to the IDE. You find how do it in my post:

How add SQL Server 2012 driver to Netbeans 8?

You must either set connection to the database. I described it in post:

Add connection in Netbeans 8 to the SQL Server 2012 database.

In this moment You may create new project. Choose from menu File->New project.

01In New Project window select from Categories section Java Web and from Project section Web Application.

02Click the Next button. In Project Name write MyNewJPA as name of your project.

a1In next step stay default options and click the Next button.

a2In New Web Application wizard select JavaServer Faces framework.

05Click the Finish button. In Projects window You see tree of your project.

a3Check if you have definition of connection to database.

07Right click on the project name and choose from Categories section Persistence and from File Types section Database Schema.

g1Click the Next button. In File Name field write mySchemaSQLServer and click the Next button.


In New File wizard select list and choose connection to your database.



g5Click the Next button. You can see available tables from database.

g6Select any tables and click the Add button.

g7These tables will move on the right side.

g9In the Projects window you see files your project.

g10Right click the name of project and choose New and Others.

a4From Categories select Persistence and from File Types choose Entity Classes from Database.

g12Click the Next button. You see window New Entity Classes from Database.

g13Click the Add All button.

g14The tablesĀ  be move on the right. Click the Next button.

g15In Package write net.doraprojects. Click the Next button.

Check Full Qualified Database … box and click the Finish button.

g16In Projects window you see new files.


In persistence.xml file you see definition of default data source.


Then you may create pages for tables class. Right click the project node and choose New->Other.


In Categories choose Persistence and from File Types select JSF Pages.


Click the Next button. In Available Entity Classes you list of table classes. Click the Add All button.

g21These class move to Selected Entity Classes section.

g22Click the Next button. In Session Bean Package field write net.doraprojects.controllers and in JSF Classes Package field write net.doraprojects.pages. Check Override existing files box.

g23Click the Finish button.

It is project tree with new files:

g24The index.xhtml file was been overwritten.

g25If you run application you see website like this:

g26If click the Show All Person link you see list of persons from test database from Person table.