【问题标题】:Use tablename in subquery which has no mapped entity class in HQL在 HQL 中没有映射实体类的子查询中使用表名
【发布时间】:2013-07-10 13:04:07
【问题描述】:
from Article as a where communityId=any(select communityId from tblcommunity where district_id=510185)

“tblcommunity”是我数据库中的一个表,我使用的是 Grails 2.2.1,异常消息是:

tblcommunity is not mapped [from com.sccn.article.Article as a where communityId=any(select communityId from tblcommunity where district_id=510185)] 

我想知道如何在 HQL 中没有映射实体类的子查询中使用表名。

【问题讨论】:

  • 如果不想映射那个表,需要直接使用sql。

标签: grails hql


【解决方案1】:

在本机查询中创建(createNativeQuery()createSQLQuery()):

select communityId from tblcommunity where district_id=510185 

然后将结果用作您的 hql 参数

where communityId in (:yourParamAsArray)

或单个结果:

where communityId = (:yourParam)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-27
    • 2011-04-13
    • 2011-09-28
    • 2021-09-15
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 2013-01-04
    相关资源
    最近更新 更多