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
Post a Comment