how to get distinct results using Projections and Criteria

后端 未结 1 769
没有蜡笔的小新
没有蜡笔的小新 2021-02-09 08:31

I am trying to load distinct Parents using Criteria in Grails. The query is as following

Query:

def criteria = Parent.createCriter         


        
1条回答
  •  被撕碎了的回忆
    2021-02-09 09:03

    You can achieve the same effect as with criteria.listDistinct if you change the criteria query to include distinct root entity results transformer like this:

        results =  criteria.list(max:params.max, offset:params.offset){
            children{
                books{
                    like('title',"%book")
                    }
                }
             resultTransformer Criteria.DISTINCT_ROOT_ENTITY            
             order("id","asc")
        }
    

    There is however a reason why grails does not return paged results for the listDistinct call so it might be a case to resort to an HQL query with the in operator

    0 讨论(0)
提交回复
热议问题