JPA For Beginners - Part 2

Step 5: Click ok for all other options. This will create a JPA project and related EAR project as below. You can see the orm.xml file, persistence.xml file and Country Entity class are created along with the project.


JPA Project Structure


Step 6: Right Click on CountryJPA, select JPA tools and click on configure JPA entities which opens the below popup.Now click on “Create New JPA Entities” and select  your schema.


Selecting DB Schema
Step 7: Now you can select the tables you needed. Since I am congiguring only for “COUNTRY”  table, I have selected it. Also you can mention the source folder and package. Step11: Now you can select the tables you needed. Since I am congiguring only for “COUNTRY”  table, I have selected it. Also you can mention the source folder and package. The next pop up will show you the available entities. select the needed one.

Generating Entities
Step 8: Click next to see the columns of your tables. Here you can add named queries which is an advanced topic. Since the table is already created and primary key is defined, it is automatically selected here. Now you will be asked for setting up the connections for deployment. All details are pre populated. Change your datasource name and Click Ok.(You can change it later also)


Step 9: Hope you have already configured the datasource for your DB in the server through administrative console. Open up your persistence.xml and add your Data source name(If not added earlier) in JTA Data Source field and change your transaction type as JTA. Now right click on the “PersistanceUnit ”  and click on “Add Class”. Browse your class and select it. Here we have only one entity called Country. Click Finish and save your persistence.xml.
In a realtime project scenario, if you have 25 tables, you need to add all the 25 java entities in persistence.xml.


Updating Persistance.xml
Click here to go to Part 3 of this demo

0 comments :

Post a Comment