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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -