Search code examples
jpaartifactjpa-2.2

JPA 2.2: which one is its API artifact to add in project?


JPA 2.2 added new feature supporting java8 stream:

 Stream Query.getResultStream();
 Stream<X> TypedQuery.getResultStream();

Tried both artifacts:

compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.2.0'
compile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'

But they do not the new stream method.

What is the right JPA 2.2 API artifact to add?

API dependency only, not provider impl.


Solution

  • From functionality point-of-view it does not matter which one is used, because both artifacts do contain these two method with exactly same (default) implementations (as expected, because so it is said in specification).

    Query:

    default Stream getResultStream() {
            return this.getResultList().stream();
    }
    

    TypedQuery:

    default Stream<X> getResultStream() {
            return this.getResultList().stream();
    }
    

    If these method are not available, reason is most likely some older JPA API on classpath before.