Java Reference
In-Depth Information
Configuring persistence
The Entity API looks great and is very intuitive, but how does the server know which data-
base is supposed to store/query the entity objects? The persistence.xml file, which
will be placed under src/main/resources/META-INF of your project, is the stand-
ard JPA configuration file. By configuring this file, you can easily switch from one persist-
ence provider to another and thus, also from one application server to another (believe it or
not, this is a huge leap towards application server compatibility).
In the persistence.xml file, we will basically need to specify the persistence provider
and the underlying data source used. Simply create the following file under src/main/
resources/persistence.xml :
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1.xsd"
version="2.1">
<persistence-unit name="primary">
<jta-data-source>java:jboss/datasources/
ExampleDS</jta-data-source>
<class>com.packtpub.wflydevelopment.chapter5.entity.Seat</class>
<class>com.packtpub.wflydevelopment.chapter5.entity.SeatType</class>
<properties>
<property
name="javax.persistence.schema-generation.database.action"
value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
Search WWH ::




Custom Search