<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jpa</artifactId>
</dependency>
JPA
Java Persistence API (JPA) is a standard JavaEE API for developing applications that need access to relational databases.
Configuration
To use JPA in your application, you need to add the JPA dependency:
and then specify the dependency for whichever JDBC Driver you need for your particular database.
Examples include:
H2 JDBC Driver
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
MySQL JDBC Driver
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
Postgres JDBC Driver
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
Usage
The jpa
fraction makes the JPA APIs available to your application through a transitive dependency.
There is no need to add them yourself.
Usage in a WAR Application
By default, inclusion of the jpa
fraction will cause the creation of the default ExampleDS
datasource for usage by your persistence.xml
.
The datasource is bound as the default datasource, so there is no need to reference it by name from your persistence.xml
.
Usage in a JAR application
If you have a .jar
-based application with a main(…)
, you can configure multiple datasources for usage with JPA.
Please see the Datasources chapter for details on configuring datasources.
Configuration
If the default datasource for JPA is used, it may be configured using system properties.
Property | Description |
---|---|
|
JDBC connection URL |
|
Username for authenticating the connection |
|
Password for authenticating the connection |
|
Simple name of the datasource, such as |