关于hql子查询的问题 急!!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/08 14:38:37
我的hql语句是:
String hql="from Attachment a left join a.TUser t left join t.TPerson left join a.domainvalueByFileDomainValue d left join a.lastCheckProblem l where a.company.id="+companyId+" and a.domainvalueByFileDomainValue.domainValue in (2001,2002,2003,2004,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016)"+"and a.id not in(select att.id from Attachment att where att.domainvalueByFileDomainValue.domainValue in (2015,2016) and att.lastCheckProblem.id is null)";
其中子查询的内容是查出id的集合,如果子查询换成sql语句在数据库上能查出结果,在我这是497,而且吧子查询语句换成497的话 结果也对,但以换成hql语句 查出的结果就不对了,哪位大侠帮忙解决下!!

问题就在于att.domainvalueByFileDomainValue.domainValue

我不知道你domainvalueByFileDomainValue是一个什么东东,但无论它是一个对象还是一个集合都涉及到了联合查询,而实际你子查询只是一个单查询而已!

既然这样你直接用sql语句就完了啊。hibernate支持sql查询