2012-03-18 88 views
1

我得到2個實體(ModTopScope和ModInstallResults)與一對許多關係JPA2 namedquery算空集麻煩

和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

OK,最後我寫了正確的querym我寫了評論,因爲我是新的網站,我的名聲還不足以回答這個問題+) SELECT DISTINCT s,COUNT(i)FROM ModTopScope s LEFT JOIN s .modInstallResults我 「+ \t \t \t \t \t 」WHERE s.modScopeType.modSystem.activated =真「 + \t \t \t \t \t 」GROUP BY的「 + \t \t \t \t \t」 ORDER BY COUNT(ⅰ)DESC – Andrey 2012-03-18 20:04:09

回答

0

OK,最後我寫的正確querym我寫評論,

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