I have two tables which are in a m:n relationship. I want to count all users in a group via an SQL (HQL) statement (to get the group with the most users)
public class User{
private String name;
@ManyToMany
private Set<Usergroup> groups;
}
public class Usergroup{
private String name;
@ManyToMany
private Set<User> users;
}
I wrote a HQL, but I always get an exception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘)
Here is my HQL:
@NamedQuery(name = "Group.countUsers", query = "SELECT g, count(g.users) FROM Group g JOIN FETCH g.users u")
What am I doing wrong?
I found the solution… It is