I have a Spring Boot project using spring-data-hazelcast 2.4.0. It is a really nice library providing HazelcastRepository which abstracts hazelcast interactions behind the standard Spring Data Repository paradigm. But I've run into the below problem when trying to do a pageable query against a list field in my object:
I have this object:
@Data
@KeySpace
public class Book implements Serializable {
@Id
private Long id;
private String author;
private List<String> categories;
}
I'd like to perform a Pageable query against the list field using HazelcastRepository. I can query within the list using the org.springframework.data.hazelcast.repository.query.Query annotation below and it works fine:
@Query("categories[any] = %s")
Iterable<Book> findByCategory(String category);
But when I try to return a Page with this method:
@Query("categories[any] = %s")
Page<Book> findByCategory(String category, Pageable pageable);
I get the below exception:
java.lang.ClassCastException: com.hazelcast.map.impl.query.QueryResultCollection incompatible with org.springframework.data.domain.Page
As an alternative, I've tried just using a derived query method like:
Page<Book> findByCategories(String category, Pageable pageable);
But that throws this exception:
java.lang.IllegalArgumentException: Cannot use EqualPredicate predicate with an array or a collection attribute
Is there a way to combine searching within a list property and returning a Page result with HazelcastRepository?
question from:
https://stackoverflow.com/questions/65883772/how-to-query-against-a-list-field-and-return-a-page-with-spring-data-hazelcast 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…