Difference between Apache Open JPA and Spring JPA

Viewed 464

I would like to know what's the key difference between Apache Open JPA and Spring JPA. Spring already has a mature JPA for dealing with all kinds of Java persistence but still saw few projects in my company where they uses Apache Open JPA. Can we integrate Apache Open JPA with Spring. Also like to know what are key benefits of Open JPA.

for example ElasticPath uses Spring but for JPA they uses Apache Open JPA

1 Answers

First: There is no Spring JPA.

There is spring-orm which is one of the many artifacts published by the Spring Framework. It contains classes dealing with JPA and it's main implementations (Hibernate and EclipsLink) in order to integrate them into the rest of the framework. Most Spring users rarely deal with it directly.

You are probably thinking of Spring Data JPA which offers repositories implemented with JPA, which in turn offer many ways to declare queries: Query derivation from method names, named queries based on method names, annotated queries, query by example, specifications ... It is part of the Spring Data project, which offers similar features with many different persistence technologies (JPA, MongoDb, Couchbase, Elasticsearch, Jdbc, Redis, Ldap ...). Spring Data JPA uses spring-orm

Since it got mentioned a couple of times now it is time to explain JPA: JPA stands for Java Persistence API and is an API which can and is implemented by multiple vendors. Hibernate is the most popular implementation, EclipseLink is the reference implementation and Apache Open JPA is another one.

Spring Data JPA (and spring-orm) are (mostly) based on JPA and therefore you should be able to use Apache Open JPA with it. But development of Open JPA was so slow in recent years that the Spring Data Team dropped OpenJPA from the JPA implementations it tests against.

To get a feeling for the development speed, you might look at the releases from the last three years (2019-2021):

As for the benefits of Apache Open JPA, I consider that an opinion question and therefore off topic for SO. But since people in your company seem to use it, I suggest asking them why they chose Open JPA over the other implementations.

Related