) I have some problem with sorting and spring pageable when I use QueryDSL. I need quite advanced sorting, not just by the fields of the object stored in the database in the same table.
This is my model in approx:
@Getter
@Setter
@Entity
public class Book {
@Id
@GeneratedValue
private long id;
@OneToMany
private Set<Category> cats = new HashSet<>()
}
@Getter
@Setter
@Entity
public class Category{
private long id;
private Name name;
}
public enum Name{
WINTER,
SUN,
SUMMER
}
Now, this what I want to do is sort (desc and asc) Book (I have many Books) by Category id only if Category has name SUN. And i want to pass Qsort as Sort interface to PageRequest sping class.
I have no idea how I can achieve it. I try many way but none of these are even close to resolve this problem (for example some subquery with invoke any() on collection and use Qsort class). I affraid I made a mistake using Query DSL rather than Criteria Api. Can someone direct me? I will be very grateful.
Best Regards