Search code examples
grailsormhqlgrails-orm

Grails: Convert the Hql query to GORM


Kindly, Convert this below hql query to GORM either using criteria or using some API. I am new to grails and I searched enough but I did't get any positive solution for this forgive me if it is simple.

MappingDetail.executeQuery("select map.id from MappingMaster as map where map.id = (select mapdetail.id from MappingDetail as mapdetail where mapdetail.rawdata_template.id=(select rawdata.id from RawDataMasterTemplate as rawdata where rawdata.name like :name))",[name:'%Rick%'])


Solution

  • Why do you have to use criteria here? I think this is the select where you use HQL instead.

    def raw = RawDataMasterTemplate.findByNameLike('%Rick%')
    def detail = MappingDetail.findByRawdata_template(raw)
    def master = MappingMaster.get(detail?.id)