我正在尝试将此sql转换为grails GORM,但不确定如何使用length函数。
这是我需要的SQL
select * from stats where length(hostname) <=0 order by hostname limit 1,10
我尝试使用http://grails.org/doc/2.2.1/ref/Domain%20Classes/createCriteria.html createCriteria,但它给了我错误消息。
如何将此SQL转换为GORM查询。
def c = Status.createCriteria()
def results = c.list (max: 10, offset: 10) {
length("hostname") <=0
}
results.each{println it}
错误消息
groovy.lang.MissingMethodException: No signature of method: grails.orm.HibernateCriteriaBuilder.length() is applicable for argument types: (java.lang.String) values: [hostname]
Possible solutions: getAt(java.lang.String), select(java.lang.String), avg(java.lang.String), count(java.lang.String), gt(java.lang.String, java.lang.Object), gte(java.lang.String, java.lang.Object)
这个HSQL有效:
def results = Status.findAll("from Status as b where " +
"length(b.hostname) <= 0 " +
"order by b.hostname asc",
[max: 10, offset: 20])
感谢