grails gorm executeQuery HQL内连接

时间:2013-01-17 17:04:14

标签: hql gorm grails-domain-class grails-controller executequery

我正在尝试使用GORM的executeQuery做一个简单的内部联接,但是得到一个QuerySyntaxException .....我相信我的hql没问题。这是我的查询

def query = Institution.executeQuery("select longName from Institution inner join TacticalIndustryCode.idInstitution")
log.info(query.size())

我也尝试了同样的错误:

def query = Institution.executeQuery("from Institution inner join TacticalIndustryCode.id")

以下是我收到的例外情况

org.hibernate.hql.ast.QuerySyntaxException: Invalid path: 'null.idInstitution' [select longName from erebus.industryGroup.Institution inner join TacticalIndustryCode.idInstitution]
    at erebus.industryGroup.TacticalIndustryCodeController$$ENunaZiV.list(TacticalIndustryCodeController.groovy:20)
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

2 个答案:

答案 0 :(得分:1)

确保您在“idInstitution”域中有一个名为“TacticalIndustryCode”的字段。

请记住,在编写HQL时,不要引用表或其列。而是使用映射的类及其属性。

答案 1 :(得分:0)

def query = Institution.executeQuery("select inst.longName from Institution as inst inner join inst.tacticalIndustryCode")

有关更多信息,请访问以下链接: http://grails.asia/grails-hql-join-examples