Java Reference
In-Depth Information
Configuring persistence
The Entity API looks great and very intuitive, but how does the server know which
database 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
standard JPA configuration file. By configuring this file, you can easily switch from one
persistence provider to another and thus also from one application server to another
(believe it, this is a huge leap towards application server compatibility).
In the persistence.xml file we will basically need to specify the persistence pro-
vider and the underlying data source used.
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/
persistence_2_0.xsd">
<persistence-unit name="primary">
<jta-data-source> java:jboss/datasources/
jbossas7development</jta-data-source>
<class>com.packtpub.as7development.chapter5.model.Seat</class>
<class>com.packtpub.as7development.chapter5.model.SeatType</class>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto"
value="create-drop" />
<property name="hibernate.show_sql"
value="false" />
</properties>
</persistence-unit>
</persistence>
Search WWH ::




Custom Search