sql-server – 将SQL查询转换为休眠标准和预测

前端之家收集整理的这篇文章主要介绍了sql-server – 将SQL查询转换为休眠标准和预测前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我从SQL查询
select e.* 
from terminal_remote_deployment e
where id = (select top 1 e1.id
            from terminal_remote_deployment e1
            where e1.Terminal_info_id = e.Terminal_info_id
            order by e1.version desc
           );

我试图用HQL写它:

final StringBuilder hql = new StringBuilder();
            hql.append(" from TerminalRemoteDeployment e");
            hql.append(" where e.id = (Select TOP 1 e1.id from TerminalRemoteDeployment e1 where e1.terminalInfo.id = e.terminalInfo.id order by e1.version desc)");

            Query query = getEntityManager().createQuery(hql.toString());
            resultList = (List<TerminalRemoteDeployment>) query.getResultList();

这种方法我遇到了错误.请帮我写一下hibernate的标准,因为我对此很新.

解决方法

第二个附加内部子查询中的Where子句.
它应该是terminal_Info_id而不是terminalInfo.id.
final StringBuilder hql = new StringBuilder();
        hql.append(" from TerminalRemoteDeployment e");
        hql.append(" where e.id = (Select TOP 1 id from TerminalRemoteDeployment e1 where e1.terminal_Info_id = e.terminal_Info_id order by e1.version desc)");

        Query query = getEntityManager().createQuery(hql.toString());
        resultList = (List<TerminalRemoteDeployment>) query.getResultList();
原文链接:https://www.f2er.com/mssql/78860.html

猜你在找的MsSQL相关文章