JPAstreamer-logo

An Open Source Library to Express Hibernate/JPA Queries as Java Streams

1. Get a Stream from any JPA Entity

1

2

3

jpaStreamer.stream(User.class)

2. Apply a Stream pipeline

1

2

3

4

5

6

jpaStreamer.stream(User.class)

    .filter(User$.age.equal("22"))

    .sorted(User$.name.reversed())

    .skip(10)

    .limit(5)

    .forEach(System.out::println)

Why JPAstreamer? 


JPAstreamer is a library for expressing JPA/Hibernate/Spring queries using standard Java streams. JPAstreamer instantly gives Java developers type-safe, expressive and intuitive means of obtaining data in database applications.

Use type-safe Java Streams

JPAstreamer provides a fully type-safe query API. This helps to instantly detect errors and allows you to utilize code-completion for increased efficiency when coding. 


Avoid complex and repetitive code

Java Stream is a declarative interface that is designed for expressing what you want, rather than how to obtain that result. As a result, your queries can be more terse while remaining expressive and intuitive to read.


Stick with a single language


With JPAstreamer, queries are expressed in pure Java. Hence you can avoid any impedances mismatches between JPQL/HQL and Java. 


User.class

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

@Entity

@Table(name = "user", schema = "mysql")

public class User implements Serializable {


  @Id

  @Column(name = "user_id", nullable = false)

  private Integer userId;


  @Column(name = "name", nullable = false)

  private String name;


  @Column(name = "age")

  private Integer age;


}

JPA Entities as the starting point


JPAstreamer relies on existing JPA entities to generate static metamodel classes needed for typesafe Stream parameters. Upon compilation, an annotation processor generates predicate field builders for all classes annotated with @Entity.

SpringEntryPoint.class (for Spring users)

1

2

@Autowired
private final JPAStreamer jpaStreamer;

Main.class (general initiation)

1

var jpaStreamer = JPAStreamer.of("mysql");

Simple initiation


JPAstreamer is generally initiated with a builder. Although, Spring users have the option to use dependency injection with the @Autowired annotation.

Main.class

1

2

3

4

5

6

jpaStreamer.stream(User.class)

    .filter(User$.age.equal("22"))

    .sorted(User$.name.reversed())

    .skip(10)

    .limit(5)

    .forEach(System.out::println)

Get a Stream from your Bean


Stream any @Entity and apply a custom pipeline to fetch relevant data. Predicates are expressed using the generated field builder, in this case User$. The actual data fetching is delegated to the JPA provider.

Stream your data effortlessly.

Features

Single dependency

Just add a single dependency to your build and start streaming. No configuration needed.

JPA Integration

Integrates seamlessly with any existing JPA provider e.g. Hibernate, Spring Data, and TopLink.

JPMS Compatible

Compatible with the Java Platform Module System (JPMS) for lightweight installation.

Standard Java API

The Java Stream API is an integral part of the Java language since Java 8 that has received praise for offering a declarative and expressive code style. 

API Extension

Enriches the API of JPA providers to include standard Java Stream as a way of expressing queries without impact on the existing application.

Self-optimizing Streams

A custom implementation of the Stream API allows shortcutting of operations to form optimal JPA queries. 

JPAstreamer is an open source Java library powered by Speedment technologies. Speedment is based in Palo Alto and is specialized on Java Streams and low-latency data processing. 

JPAstreamer Announcements

Copyright © 2020 Speedment, Inc. All rights reserved.