Sql to Hql query in grails for a very large assosiation -
in app there's following relation: page hasmany paragraphs , need create query returns pages number of paragraphs less limit. problem pages created in app approximately 2 per second , paragraphs table contains more 2 million rows. standard grails approaches, dynamic finders , criteria queries hang create not optimal sql. in database console following query job:
select * ( select a.id, count(b.page_id) count page left join paragraph b on a.id = b.page_id group 1) sub sub.count <= 10 limit 1000
and couln't translate query hql. know there's groovy sql available, it's rows method returns list of groovyresult, not list of domain classes. there better approach issue?
if query gets complicated tend this:
def results = new sql(datasource).rows(sql)*.id*.astype(integer).colect(domainclass.&get)
i know doesn't great , you'd probable no kudos gets job done. if you'd use more expressive give try jooq (http://www.jooq.org/)
Comments
Post a Comment