Is there some good way for dynamic search conditions, like spring data jpa ExampleMatcher

In my scenario, there are several search parameters like age, gender and height. The parameter could be empty if user doesn’t input. So we need to remove the empty parameter in the where clause. For example, if user just input age, then the search condition should be where age = xxx, if user input age and gender, the search condition should be where age = xxx and gender = xxx.

I just use spring data couchbase which support repository.findbyXXX, but I found the couchbase repository doesn’t ExampleMatcher. when I try to add extends JpaRepository, I got the error “CouchbaseRepositoryFactory does not support Query by Example”. Is there good way to support this requirement?

spring data couchbase supports querydsl. Spring Data Couchbase - Reference Documentation

Or the template findByQuery() method with a ‘matching(query)’

		Query specialUsers = new Query(QueryCriteria.where(i("firstname")).like("special"));
		final List<User> foundUsers = couchbaseTemplate.findByQuery(User.class).

wow cool! Thanks! Previously I also explored querydsl and template findByQuery but both failed. The reason is spring-data-couchbase is not the latest, we used 4.3.0 in the project. Let me upgrade the jar and try again.

Hi Michael @mreiche , as our project is using spring-boot 2.7.14 and cannot be upgraded to spring boot 3.0 recently. So I have to use spring-boot-starter-data-couchbase:2.7.14 in which spring-data-couchbase is 4.4.14.
I find one issue is this version of spring data couchbase doesn’t support Sort. In createSort method of class SpringDataCouchbaseQuerySupport, it always return null and finally get the error of Sort cannot be null. I check 5.1.3 and this method has implementation in that version. Is there some work around to solve this issue using 4.4.14?
protected Sort createSort(List<OrderSpecifier<?>> orderSpecifiers) {
return null;

ok - I pulled it in to 4.4.x. It will be in the next release (4.4.16) which is scheduled for September 15.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.