I know I’ve previously written about how Spring Security just might be my favorite project. However, that opinion had to be put on the shelf when I realized that Spring Integration might actually be my favorite project. It’s really tough to hold onto that opinion when I stopped to realize how Spring MVC might be favorite project.
But I’ve been thinking real hard since I wrote those articles. And I have to be honest. Truthfully, spiritually, ecumenically honest.
Spring Data is ACTUALLY my favorite Spring project.
Spring Data is the thing that makes application development really sizzle. Why? Because every application has data. What kind of app doesn’t?
The number of times I’ve needed some quick-and-dirty solution to grab a piece of data, Spring Data lets me jump right to it using custom finders. Custom finders let you define all the details of a query with a simple method signature. No implementation. No Hibernate query. No SQL query. Just a method name and the parameters. Spring Data will write the query for me.
Just look at this example. These are three different custom finders.
- The first one fetches a List of User domain objects based on a complete match of the firstName field. The user supplies not just the firstName, but also a Pageable, meaning you can pick the page of date you’ll get back.
- The second one fetches a Page of User domain objects using the same page-based filtering. But instead of matching on a single firstName, it instead does a WHERE first_name IN (:firstNames) type criteria, allowing you to find multiple matches.
- The third one is much more details. It find the first three User domain objects that match the firstName exactly against a result set ordered by firstName ascending and emailAddress ascending. But does it through Spring Data JPA’s new scroll API, meaning that you can fetch a Window of data, then move to the next window smoothly, and without being confined to the same page size for each iteration!