Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

spring

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

like image 877
alex Avatar asked Mar 25 '26 21:03

alex


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. 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.

like image 61
kwkw Avatar answered Mar 27 '26 11:03

kwkw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!