【问题标题】:hql query outer joinhql查询外连接
【发布时间】:2019-01-30 08:32:04
【问题描述】:

大家好,我正在尝试使用 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>

【问题讨论】:

  • 查看日志。您可能会在那里发现错误。您的 sql 无效。

标签: java hibernate iterator hql


【解决方案1】:

正确的 SQL 是

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

【讨论】:

    猜你喜欢
    • 2010-12-22
    • 1970-01-01
    • 2013-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多