OK, I have mapped with annotations two tables with a bidirectional @ManyToMany relationship.
Now I want to return only the elements which aren’t in a many to many relationship, and I’m trying to use the code from here, but It throws an exception at runtime.
Here’s the HQL:
String hql = "select a from Article a " +
"left join a.tags t " +
"group by a " +
"having count(t)=0";
Is there a better way to return those elements? Or to fix the error in this query?
The exception it throws now is:
column "article0_.id" must appear in the GROUP BY clause or be used in an aggregate function
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL ...
The query is correct, but on some databases
group by ais not enough, you have to enumarate all properties ofa, such asgroup by a.id, a.title.Alternatively, you can use the following query:
See also: