문제

I'm passing a list of IDs called statuses from the view to the controller. In the controller I'm simply executing:

def statusSelection = params.list('statuses')

I'm using createCriteria to then fetch a list of domain-class records:

MyDC.createCriteria().list(
    max: params.max,
    offset: params.offset,
    order: params.order,
    sort: querySort) {
        statuses { // hasMany statuses: Status
            or {
                statusSelection.each { // loop through params list
                    idEq(it.id)
                }
            }
        }
    }

This has been working fine until the requirements requested the table in the view allow for sorting of the status property. Now I'm getting a org.hibernate.QueryException with the following message:

duplicate association path: statuses

This is due to the querySort value I'm sure, but I don't know how to alias the sort and maintain the or statement.

도움이 되었습니까?

해결책

If when error raise querySort == "statuses" then you can create alias to replace that querySort. You should change your gsp to return statusSort instead statuses

MyDC.createCriteria().list(
max: params.max,
offset: params.offset,
order: params.order,
sort: querySort) {
    createAlias('statuses', 'statusSort') //This alias will replace the querySort 
    statuses { // hasMany statuses: Status
        or {
            statusSelection.each { // loop through params list
                idEq(it.id)
            }
        }
    }
}

You can read a very interesting discussion here: Sorting on database server or application server in n-tier architecture

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top