26

I am using JPA 2.0 and my persistence provider is Hibernate; however, I'd like to just include a standard API from javax, but in central, there is no 2.0 artifact. I am currently using the Hibernate JPA 2.0 artifact, but I'd like to use something more standard.

Is this possible?

Thanks,

Walter

4 Answers4

18

I am currently using the Hibernate JPA 2.0 artifact, but I'd like to use something more standard

There is still no javax.persistence:persistence-api:jar:2.0 artifact from Sun/Oracle. Either use the full javax:javaee-api:jar:6.0 artifact if you want something from Sun/Oracle... or just stick with the interfaces provided by Hibernate, EclipseLink, OpenJPA, etc.

Laurent Pireyn
  • 6,627
  • 1
  • 28
  • 39
Pascal Thivent
  • 549,808
  • 132
  • 1,049
  • 1,115
11

Currently (Q1 2020) the default artifact is

<dependency>
  <groupId>jakarta.persistence</groupId>
  <artifactId>jakarta.persistence-api</artifactId>
  <version>2.2.3</version>
</dependency>

An older artifact of javax.persistence-api is also available at maven central, but is superseded by the jakarta version.

<dependency>
  <groupId>javax.persistence</groupId>
  <artifactId>javax.persistence-api</artifactId>
  <version>2.2</version>
</dependency>

The code is maintained in this github repo.

rmuller
  • 10,931
  • 4
  • 58
  • 86
9

As Ivan explains, there are no official Sunacle jars in Maven. However, it is quite often the case that an implementer of a given API will publish an artifact for that API (the API itself, rather than their implementation of it.

In the case of JPA 2.0, Hibernate publish org.hibernate.javax.persistence:hibernate-jpa-2.0-api, which contains just the javax.persistence classes, and no Hibernate-specific stuff.

My build.gradle therefore says:

dependencies {
    compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.0-api', version: '1.0.1.Final'
    runtime group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.1.4.Final'
}

Which puts Hibernate's release of the API on the compile classpath, and their implementation on the runtime classpath.

Tom Anderson
  • 44,913
  • 16
  • 86
  • 129
  • Every major provider seems to have their own `javax.persistence` classes. Which is just stupid as you'd think there would be one by 2016 that is the canonical one for JPA 2.0, 2.1, etc... – Powerlord May 11 '16 at 21:43
2

The direct answer to your questions is: No, it's not possible. The longer version is given here: Apache > Maven > Guide to Coping with Sun JARs . A short summary of the longer answer:

There are (at least) two problems with publishing Sun/Oracle artifacts in central repository:

  1. Restrictive license
  2. Naming convention
Ivan Hristov
  • 2,780
  • 2
  • 22
  • 22