Grails: domain object sort mapping not working

♀尐吖头ヾ 提交于 2020-05-16 21:58:33

问题


Here is my domain object:

package org.olr.nonadmin
import org.olr.admin.User

class Question {
//  Integer id // autogenerated by db
//  Integer version // autogenerated integer
    Date dateCreated  // auto filled
    Date lastUpdated  // auto filled
    String qText        // question text - can contain markup!
    String aText        // answer text - can contain markup!
    boolean publik      // public to all usersot needed
    String figureBase64 // image in BASE64 format, used in data-URI for figure
    String figureName   // figure name (for documentation)
    Integer format      // how to format for projector display
    Integer difficulty  // e.g. 1 (easy), 2 (medium), 3 (hard)
    Integer gradeLevel  // grade: 5,6,7,8,9

    static belongsTo = [owner: User]
    User owner;         // filled by controller save() method

    static constraints = {
        id generator: 'identity'
        owner nullable: false, editable: false
        qText sqlType: 'text', nullable: false, widget: 'textarea'
        aText sqlType: 'text', nullable: false
        figureBase64 sqlType: 'text', nullable: true, blank: true, maxSize: 1024*12
        figureName nullable: true, blank: true
        format min: 0, max: 5, sqlType: 'smallInt', nullable: true, blank: true
        difficulty min: 1, max: 4, sqlType: 'smallInt', nullable: true, blank: true
        gradeLevel min: 6, max: 8, sqlType: 'smallInt', nullable: true, blank: true
    }

    static mapping = {
        sort id: "asc"
    }

    @Override
    String toString() {
        return "${id}"
    }

}

Notice that I would like all Hibernate queries to return Question objects in id order.

Here is the service by which data is retrieved from the Question table:

package org.olr.nonadmin

import grails.gorm.services.Service
import org.olr.admin.User

@Service(Question)
interface QuestionService {

    Question get(Serializable id)
    List<Question> list(Map args)
    List<QuestionFile> findByOwner(User owner)  // Added, but implemented by GORM service
    Long count()
    void delete(Serializable id)
    Question save(Question question)

}

When my index view retrieves data (which due to editing has changed the physical order of rows on disk) the data is not listed in id order:

The data is in the order that a raw SELECT statement returns:

Why is

    static mapping = {
        sort id: "asc"
    }

being ignored?

Grails ver. 3.3.1 POSTGRES ver. 11.2

Note: I tried using dateCreated as the sort key -- no luck. Also tried qText as the sort key without success.

来源:https://stackoverflow.com/questions/61489171/grails-domain-object-sort-mapping-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!