1. Overview

By default, Spring Data uses Hibernate as the default JPA implementation provider.

However, Hibernate is certainly not the only JPA implementation available to us.

In this article, we’ll go through steps necessary to set up EclipseLink as the implementation provider for Spring Data JPA.

2. Maven Dependency

To use it in our Spring application, we just need to add the org.eclipse.persistence.jpa dependency in the pom.xml of our project:

<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.jpa</artifactId>
    <version>2.7.0</version>
</dependency>

By default, Spring Data comes with the Hibernate implementation.

Since we want to use EclipseLink instead as the JPA provider, we don’t need it anymore.

Therefore we can remove it from our project by excluding its dependencies:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>

The next step is to tell the Spring Framework that we want to use EclipseLink as the JPA implementation.

3. Spring Configuration

JpaBaseConfiguration is an abstract class which defines beans for JPA in Spring Boot. To customize it, we have to implement some methods like createJpaVendorAdapter() or getVendorProperties().

Spring provides a configuration implementation for Hibernate out of the box called HibernateJpaAutoConfiguration. However, for EclipseLink, we have to create a custom configuration.

First, we need to implement the createJpaVendorAdapter() method which specifies the JPA implementation to use.

Spring provides an implementation of the AbstractJpaVendorAdapter for EclipseLink called EclipseLinkJpaVendorAdapter that we’re going to use in our method:

@Configuration 
public class EclipseLinkJpaConfiguration extends JpaBaseConfiguration { 

    @Override 
    protected AbstractJpaVendorAdapter createJpaVendorAdapter() { 
        return new EclipseLinkJpaVendorAdapter(); 
    }
    
    //...
}

Also, we have to define some vendor-specific properties which will be used by EclipseLink.

We can add these via the getVendorProperties() method:

@Override
protected Map<String, Object> getVendorProperties() {
    HashMap<String, Object> map = new HashMap<>();
    map.put(PersistenceUnitProperties.WEAVING, true);
    map.put(PersistenceUnitProperties.DDL_GENERATION, "drop-and-create-tables");
    return map;
}

The class org.eclipse.persistence.config.PersistenceUnitProperties contains properties which we can define for EclipseLink.

In this example, we’ve specified that we want to use weaving and re-create the database schema when the application runs.

And that’s it! This is the whole implementation necessary to change from the default Hibernate JPA provider to EclipseLink.

Note that Spring Data uses the JPA API and not any vendor specific methods. So, in theory, there should be no problem when switching from one vendor to another.

4. Conclusion

In this quick tutorial, we covered how to change the default JPA implementation provider used by Spring Data.

We saw how quick and simple it is to change from Hibernate which is the default to EclipseLink.

As always, the full implementation of the examples is available over on Github.