Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Tutorial - Set Up A Web Dynamic Project As JPA

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

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 persistence.xml 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="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<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 persistence.xml.

<?xml version="1.0" encoding="UTF-8"?>


<persistence version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="JPAExample">
<jta-data-source>TIWDS</jta-data-source>
<class>entities.Usuario</class>
</persistence-unit>
</persistence>

You might also like