2014-10-30 26 views
0

當我寫這個的HQL:的Grails的FindAll順序按不工作HQL

tempDocs = Document.findAll("FROM Document where docName LIKE :docn ORDER BY status asc",[docn:string],[max:limit, offset:startIndex]) 

是正確的工作。 但是,當我試圖通過編寫

tempDocs = Document.findAll("FROM Document where docName LIKE :docn",[docn:string],[max:limit, offset:startIndex,sort:column,order:ordering]) 

來概括呢?這似乎並沒有給出正確的順序。這裏出了什麼問題?

+0

你能試試我的建議嗎? – th3morg 2014-11-21 01:34:21

回答

0

根據findAll的文檔,對於queryParams只有三個選項:max,offset,cache。作爲您的兩個示例的混合體,您可以提供排序和命令作爲命名參數。

tempDocs = Document.findAll("FROM Document where docName LIKE :docn ORDER BY :sort :order",[docn:string],[max:limit, offset:startIndex,sort:column,order:ordering]) 
0

我th3morg的溶液中引起以下情況除外:

類 org.hibernate.hql.internal.ast.QuerySyntaxException 消息 意外的標記:鄰近行1,列89 [FROM receiptbucketserver。收據,其中project.customer.id =:客戶ID ORDER BY:排序:爲了]

我的語法看起來這樣的(這可能是錯誤的,我不是專家) Receipt.findAll(「從接到哪裏project.customer .id =:customerId ORDER BY:排序:序」,[客戶:customer.id],[排序:列順序:排序])

我能得到它具有非常難看工作:

Receipt.findAll("from Receipt as r where r.project.customer.id = :companyId ORDER BY " + field + " " + sortOrder , [companyId: customer.id]) 

所謂的:

def listReceipts = receiptHelperService.getReceiptsByCustomer(customerInstance, "vendor", "desc")