The widely used Spring Framework and its module Spring Data JPA encourage using queries the way I described
That’s new to me. Can you show me a reference where this is explicitly stated?
This repository method generates a Hibernate query and makes providing departments mandatory (empty list returns 0 result, null returns IllegalArgumentException).
Because this implies that nobody encourages this kind of usage.
Spring 5 (with Hibernate 5) made it easy to provide optional departments:
I’m sorry you based part of your application on something unspecified which just happened to work in this particular case, but like I wrote before, this kind of query is very inefficient. Don’t use that. Go the extra mile and implement proper conditional filtering.
With Spring 6 (including Hibernate 6) I have to implement it via Criteria API and Custom Repositories, which is more costlier and verbose
You don’t. I’d suggest everyone to use Spring Data Specification here for this purpose.
|