我有两个实体(ModTopScope和ModInstallResults),一对多关系
和NamedQuery:
@NamedQuery(name="ModTopScope.getScopesForActiveSystems",
query="SELECT s, COUNT(s.modInstallResults) FROM ModTopScope s LEFT JOIN FETCH s.modInstallResults " +
"WHERE s.modScopeType.modSystem.activated = true " +
"GROUP BY s " +
"ORDER BY COUNT(s.modInstallResults) DESC")
没关系,除了ModTopScope的查询结果列表中没有记录,ModInstallResults表中没有相应的记录。我该如何解决?
本机sql,用于选择在mod_install_resutls表中没有相应记录的记录:
select s.id, count(i.id) from mod_top_scopes s left join mod_install_results i on s.id=i.scope_id group by s.id order by count(i.id)
答案 0 :(得分:0)
好的,最后我写了正确的查询,我写了评论,
SELECT DISTINCT s, COUNT(i) FROM ModTopScope s LEFT JOIN s.modInstallResults i " + "WHERE s.modScopeType.modSystem.activated = true " + "GROUP BY s " + "ORDER BY COUNT(i) DESC