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 one of the following dependencies:

Default using H2 JDBC Driver

<dependency>
  <groupId>org.wildfly.swarm</groupId>
  <artifactId>jpa</artifactId>
</dependency>

Default using MySQL JDBC Driver

<dependency>
  <groupId>org.wildfly.swarm</groupId>
  <artifactId>jpa</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>h2</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.wildfly.swarm</groupId>
  <artifactId>mysql</artifactId>
</dependency>

Default using Postgres JDBC Driver

<dependency>
  <groupId>org.wildfly.swarm</groupId>
  <artifactId>jpa</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>h2</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.wildfly.swarm</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

swarm.ds.connection.url

JDBC connection URL

swarm.ds.username

Username for authenticating the connection

swarm.ds.password

Password for authenticating the connection

swarm.ds.name

Simple name of the datasource, such as ExampleDS