what's wrong with this HQL query?

做~自己de王妃 提交于 2019-12-12 05:26:46

问题


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

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