java - 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>
解决方案
正确的 SQL 是
select u.*, d.* from Units u outer join Depts d on d.deptId=u.depts
推荐阅读
- java - 用一周的日期转换字符串
- flutter - 如何在使用 google_nav_bar Flutter 单击选项卡时切换类
- ruby-on-rails - Ruby On Rails 使用错误的版本执行
- r - 替换以美元符号开头的句子中的所有单词
- case - 在语句 -Snowflake 的情况下,无法连接基于不同列的值
- c++ - 有没有办法有条件地初始化全局静态变量?
- node.js - 没有堆栈跟踪的节点/TS 节点崩溃
- python - Python:以3列格式显示两个文件并计算相似词的频率
- reactjs - 如何解决 reactDOM.render 的错误
- reactjs - 使用 axe 进行 React Native 测试:所有页面内容都应包含在地标(区域)中