问题
I'm executing the following HQL query in my Grails app:
def maxIndex = VirtualSubOrder.find(
'select max(vso.index) from VirtualSubOrder vso where vso.virtualOrder = ?',
[virtualOrder])
The VirtualSubOrder
class definitely has an (Integer) index
property and a virtualOrder
property.
When I try to execute the query above I get the error:
org.codehaus.groovy.grails.orm.hibernate.exceptions.GrailsQueryException: Invalid query [select max(vso.index) from VirtualSubOrder vso where vso.virtualOrder = ?] for domain class [class com.example.VirtualSubOrder]
回答1:
I believe you want to use VirtualSubOrder.executeQuery()
instead of find()
. find
is for returning domain instances and executeQuery
is for arbitrary HQL.
来源:https://stackoverflow.com/questions/13747950/whats-wrong-with-this-hql-query