In this simple example we are going to see how to use java streams with JPA thanks to JPAstreamer.
JPAstreamer is a library for expressing JPA/Hibernate/Spring queries using standard Java streams.
To use JPAstreamer together with Spring Boot we need to add maven dependencies and inject as dependency JPAStreamer in every class that we want to use it.
To work with JPAstreamer in our classes we are going to use it as Java Stream. For example if we want to find all records of car entity we are going to do:
jpaStreamer.stream(Car.class) .collect(Collectors.toList());
We also have to keep in mind that we need spring-boot-starter-data-jpa.
This is a spring boot application so to run it you can run with maven:
mvn spring-boot:run
from your IDE running the class
JpastreamerExampleApplication
or running your *.jar
java -jar *.jar
We have some endpoints with GET to verify and check this example:
-Brand http://localhost:8090/brand/ http://localhost:8090/brand/{id} http://localhost:8090/brand?name={Name}
-Car http://localhost:8090/car/{id} http://localhost:8090/car
Examples: http://localhost:8090/brand/2 http://localhost:8090/brand?name=Mercedes http://localhost:8090/car/1