TUTORIAL: Set up a Web Dynamic project as JPA
When creating a JPA project we have two options:
a) Create it as “JPA Project” from start
b) Take an existing “Dynamic Web” project and add it a JPA facet
In this tutorial we are going to follow the steps required for the second option: we will
take an existing “Dynamic Web” project and we will convert it into a JPA project. We
will use a DataSource previously created to connect with the database.
otherwise, once created, right click on the project and click on properties>Project Facets
1. Right click on the laboratories project and select : Configure-> JPA project to
convert ...
2. In the dialog that appears make sure that Payara is selected as Runtime
3. Press Next in the following screen select in JPA implementation: Payara System
Library
Window>Perspective>Open Perspective>JPA
4. Press Finish and it will generate a new [Link] descriptor within a
META-INF directory. Open it with a double click.
it's in the JPA Content dir
5. In the window that appears change these values:
• Name: laboratoriosPU (or any other name you choose)
6. At the bottom of the editor changes the Connection tab and apply the following
values
Nombre del
DataSource
name in JDBC Resources
in Payara admin console
(port 4848)
7. Save changes
You should have a code that looks like the following (by clicking on the source tab):
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" xmlns="[Link]
xmlns:xsi="[Link] xsi:schemaLocation="[Link]
[Link]
<persistence-unit name="JPAExample">
<jta-data-source>TIWDS</jta-data-source>
</persistence-unit>
</persistence>
Now you can start adding entities to your project. You will see that as you add them
they name will appear in the file [Link].
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" xmlns="[Link]
xmlns:xsi="[Link] xsi:schemaLocation="[Link]
[Link]
<persistence-unit name="JPAExample">
<jta-data-source>TIWDS</jta-data-source>
<class>[Link]</class>
</persistence-unit>
</persistence>