java - Hibernate do a projection of count alias -


here code:

   class a{      integer id      string name      set<b> bs;       //getters , setters }  class b{      integer id;      a;       //getters , setters } 

i need consult rows of a, , each row need know hoy many b reference a.

i have sql query, dont know how hibernate in java

simplificated query:

select     a.id y0_,     ( select count(*)          b b          b.c47=a.id          , b.fdl='n'          ) count,     a  inner join     c c          on a.operario=c.id      a.did=2     , a.fdl='n' 

thanks in advance

@entity @table(name = "a_table") class {     @id     @generatedvalue     integer id;      @column      string name;      @onetomany(mappedby = "a")     set<b> bs;       //getters , setters }  @entity @table(name = "b_table") class b {     @id     @generatedvalue     integer id;      @manytoone(fetch = fetchtype.lazy)     @joincolumn(name = "a_id")     a;       //getters , setters } 

the hql:

select a.id, count(bs) a left join a.bs bs inner join a.c c      a.id = 2      , a.fdl='n'     , bs.fdl='n' 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -