I am trying to develop a social network in Angular and Spring.
I have users and they can follow eachother.
My User class looks something like this.
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long userId;
@OneToMany(mappedBy = "following")
private List<Follow> followers;
@OneToMany(mappedBy = "follower")
private List<Follow> following;
}
Is there anyway I can get all the users ordered by the number of followers?
2
Answers
In your UserRepository you could try the following…
Taking full advantage of JPA. Hope this helps.
I have definitely done this in MySQL; I don’t have the query where I did this right on hand though.
I think it is something like