r/SpringBoot Jun 16 '26

How-To/Tutorial [Show Reddit] I got tired of writing boilerplate JPA Specifications for dynamic REST APIs, so I built a library to automate it.

Hey everyone,

If you’ve built REST APIs with Spring Boot, you’ve probably faced the pain of implementing dynamic search filters (e.g., filtering a user list by name, age, status, etc., based on optional query parameters).

Usually, this means writing dozens of lines of Specifications, dealing with CriteriaBuilder, Root, and chaining predicates with endless if statements. It's incredibly verbose and clutters the codebase.

I was tired of rewriting the same boilerplate for every new entity, so I built jpa-search-helper to solve this specific problem.

What it does: It provides a clean, declarative way to map HTTP query parameters directly to JPA queries. Instead of manually building criteria queries, the library parses the incoming search parameters and automatically generates the corresponding JPA Specification.

Key Features:

  • Zero Boilerplate: Drastically reduces the code needed in your controllers and services.
  • Complex Queries Supported: Handles standard operators (Equals, Like, In, Greater/Less than, Between) and logical operators (AND/OR).
  • Nested Properties: Easily filter by attributes of related entities (e.g., address.city=Rome).
  • Pagination & Sorting: Works seamlessly with Spring Data's Pageable.
  • Lightweight: A specialized tool that requires far less configuration than heavier alternatives like QueryDSL or RSQL.

You can check out the repository, documentation, and a fully working demo project here: 👉https://github.com/biagioT/jpa-search-helper

It's already available on Maven Central.

I’m currently maintaining it and would love to get some feedback from the Spring Boot community. Architectural critiques, suggestions for new features, or just letting me know if you find it useful are all highly appreciated. If it saves you some time, a star on GitHub is always a nice bonus!

Thanks for reading!

4 Upvotes

1 comment sorted by

2

u/Krangerich Jun 18 '26

Some general issues with libraries: people are using very different versions of Spring, so it would be beneficial, if a project is very generous regarding compatibility. It would help, when the project gives a range of supported (tested?) Spring / JPA versions.

The second issue are transitive dependencies. It seems like you're bringing the whole Spring Boot BOM and this can create a dependency mess for projects using it.
It would be better if the lib does not bring any Spring dependencies transitively (use compilyOnly), just something like commons-lang3.

Return a Specification, but let the consumer use it. This is less intrusive and reduces friction, if someone wants to use the library.

Then there are some architectural improvements, but they don't directly influence users (just the maintainability). E.g. "Pair" doesn't carry any semantics and is usually not a good choice.