在子查询中使用tablename,它在HQL中没有映射的实体类

时间:2013-07-10 13:04:07

标签: grails hql

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)] 

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

1 个答案:

答案 0 :(得分:0)

在原生查询中创建(createNativeQuery()createSQLQuery()):

select communityId from tblcommunity where district_id=510185 

然后将结果用作hql param

where communityId in (:yourParamAsArray)

或单个结果:

where communityId = (:yourParam)