-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Description:
Hello everyone, and especially the Spring Boot community 👋
I'm currently facing a small issue while working with JPA Specifications. Because my entity has a large number of fields, I’d like to perform database-level projections instead of memory-based projections for performance reasons.
From my understanding, the only way to achieve this is by using the CriteriaBuilder API directly. However, before taking that route, I wanted to ask for guidance or best practices.
Questions:
Is there a recommended approach to perform projections at the database level when using JPA Specifications?
Can this be integrated cleanly with Spring Data’s specification infrastructure, or is CriteriaBuilder the only option?
Environment:
Spring Boot version: 3.4.4
JPA provider: Hibernate
Database: PostgreSQL
`
Sort sort = buildSort(searchQuery.getSortBy(), searchQuery.getSortDir());
PageRequest pageable = PageRequest.of(searchQuery.getPageIndex(), searchQuery.getPageSize(), sort);
return orderEntityRepository.findBy(
specification,
query -> query
.as(OrderSearchView.class)
.sortBy(sort)
.page(pageable)
.map(orderEntityMapper::toMechanicalShopSearchResponse));
}
`