I have a dilemma on how to sort a column by the count of an entity from another table.
I have two entities
@Entity
public class Plan {
Long id;
String name;
PlanStatus status;
LocalDateTime dateCreated;
LocalDateTime lastUpdated;
}
@Entity
public class Subscription {
Long id;
Plan plan;
Right now, I just directly passed the Sort sort for the repository implemented with Pagable (pageRequest)
return smsPlanRepository.findAll(planSpecification, pageRequest);
But is there a way where I could use Specification with the number of Subcriber of each Plan?
public Specification<Plan> hasSort(String sortBy) {
return (root, query, criteriaBuilder) -> {
return //count of by Plan in Subscribers
}
}
Thank you for your help in advance!