org.openrewrite.java.migrate.javaee7.OpenJPAPersistenceProvider
When migrating to EclipseLink, using OpenJPA providers in EclipseLink results in runtime errors. To resolve these errors, the recipe removes the flagged OpenJPA provider from the persistence.xml.
Recipe source
GitHub: java-ee-7.yml, Issue Tracker, Maven Central
This recipe is available under the Moderne Source Available License.
Definition
- Recipe List
- Yaml Recipe List
- Change XML tag value
- elementName:
/persistence/persistence-unit/provider - oldValue:
org.apache.openjpa.persistence.PersistenceProviderImpl - newValue:
org.eclipse.persistence.jpa.PersistenceProvider
- elementName:
Used by
This recipe is used as part of the following composite recipes:
Examples
Example 1
OpenJPAPersistenceProviderTest#openJPAPersistenceProvider
- xml
- Diff
Before
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
version="1.0">
<persistence-unit name="JPAService">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService1">
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService2">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService3">s
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService4">
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
</persistence-unit>
</persistence>
After
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
version="1.0">
<persistence-unit name="JPAService">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService1">
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService2">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService3">s
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService4">
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
</persistence-unit>
</persistence>
Example 2
OpenJPAPersistenceProviderTest#openJPAPersistenceProvider
- xml
- Diff
Before
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
version="1.0">
<persistence-unit name="JPAService">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService1">
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService2">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService3">s
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService4">
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
</persistence-unit>
</persistence>
After
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
version="1.0">
<persistence-unit name="JPAService">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService1">
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService2">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService3">s
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:comp/env/jdbc/DB2Connection</jta-data-source>
<class>my.jpa.Account</class>
</persistence-unit>
<persistence-unit name="JPAService4">
<provider>com.ibm.websphere.persistence.PersistenceProviderImpl</provider>
</persistence-unit>
</persistence>
Usage
This recipe has no required configuration options. It can be activated by adding a dependency on `org.openrewrite.recipe:rewrite-migrate-java` in your build file or by running a shell command (in which case no build changes are needed):
- Gradle
- Gradle init script
- Maven POM
- Maven Command Line
- Moderne CLI
- Add the following to your
build.gradlefile:build.gradle
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.java.migrate.javaee7.OpenJPAPersistenceProvider")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.31.1")
} - Run
gradle rewriteRunto run the recipe.
See how this recipe works across multiple open-source repositories

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.
Data Tables
- SourcesFileResults
- SearchResults
- SourcesFileErrors
- RecipeRunStats
Source files that had results
org.openrewrite.table.SourcesFileResults
Source files that were modified by the recipe run.
| Column Name | Description |
|---|---|
| Source path before the run | The source path of the file before the run. null when a source file was created during the run. |
| Source path after the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
| Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. |
| Recipe that made changes | The specific recipe that made a change. |
| Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. |
| Cycle | The recipe cycle in which the change was made. |