org.springframework.data.domain.Sort why the error

Viewed 8008

I use org.springframework.data.domain.Sort:

Sort sortDesc = new Sort(Sort.Direction.DESC, "id");

as in the examples. But I get an error: Error:(47, 55) java: incompatible types: java.lang.String cannot be converted to java.util.List<java.lang.String>

I tried this:

List<Sort.Order> orderList = new ArrayList<>();
orderList.add(new Sort.Order (Sort.Direction.ASC, "id"));
Sort sort = new Sort(orderList);

But I get an error:

Error:(55, 21) java: Sort(java.util.List<org.springframework.data.domain.Sort.Order>) has protected access in org.springframework.data.domain.Sort

1 Answers

I suspect you are trying to Sort data from your Spring Data JPA. You cannot call Sort and instantiate it, to my knowledge. You might have been looking for something like:

List<Item> item = repository.findAll(Sort.by(Sort.Direction.DESC, "id");

As you can see in the documentation, Sort has a protected constructor and cannot be called directly in the way you are trying to instantiate it. [https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/Sort.html][Spring Documentation on Sort]

I am missing too much information about the rest of your project and how you setup your data with Spring Framework to give any other information.

Related