问题
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