首页 > 解决方案 > hql查询外连接

问题描述

大家好,我正在尝试使用 hql 进行外部联接并迭代检索到的列以显示它。下面的代码没有显示错误,也没有输出。

<html>
<body>
<%
           try {
    SessionFactory sf=  new Configuration().configure().buildSessionFactory();
    Session s= sf.openSession();
    Query e=s.createQuery("select u.*, d.* from Units u,Depts d outer join d.deptId=u.depts");
    Iterator i= e.iterate();
            out.println("<table>");
            while(i.hasNext())
            { 
            Units l= (Units)i.next();
            Depts v= (Depts)i.next();;
            out.println("<tr><th>"+l.getUnitId());
            out.println("<th>"+v.getDeptName());
            out.println("<th>"+l.getUnitName());
            }
            } catch (Exception he) {
                he.printStackTrace();}
        %>
</body>
</html>

标签: javahibernateiteratorhql

解决方案


正确的 SQL 是

select u.*, d.* from Units u outer join Depts d on d.deptId=u.depts

推荐阅读