hibernate - JPA Left Join and Count -
i want retrieve foo objects , every foo object number of associated bar objects (zero or more) database. want in one single query , don't want fetch lists of bar objects sizes.
the following works, returns foo objects have matching bar objects:
@namedquery(name = "foo.findandcountbars", query = " select new com.test.myresultcontainer(f, count(b.id)) foo f, bar b f.uniquekey = b.uniquekey group f.id ") notice foo , bar not connected via primary keys. following want achieve (without explicit relationship such @onetomany in foo):
@namedquery(name = "foo.findandcountbars", query = " select new com.test.myresultcontainer(f, count(b.id)) foo f left join bar b on f.uniquekey = b.uniquekey group f.id ") i tried different syntax variations, eclipse tells me b.id unknown because bar not in from clause. how can this?
Comments
Post a Comment