对含有many-to-one外键的查询的问题

ming1683 2007-03-05 06:29:15
<%
org.hibernate.Session s = HibernateSessionFactory.currentSession();
String hql = "from Xmb where dl=:dl order by xh asc";
Lbb dl = (Lbb)s.get(Lbb.class, new Integer(1));
List list = s.createQuery(hql).setEntity("dl", dl).list();
Xmb xmb = null;
for (Iterator its = list.iterator(); its.hasNext(); ) {
xmb = (Xmb)(Object)its.next();
。。。。。(读数据)
}
HibernateSessionFactory.closeSession();
xmb = null;
list = null;
hql = null;
%>


报错:
org.hibernate.exception.SQLGrammarException: could not execute query
=========================

Lbb dl = (Lbb)s.get(Lbb.class, new Integer(1));是没有问题的,试验过,成功得到持久化类
不知出了什么问题?
...全文
321 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ming1683 2007-03-07
  • 打赏
  • 举报
回复
解决了。取了别名就正常了:

from Xmb x where x.dl = :dl order by x.xh asc
ming1683 2007-03-07
  • 打赏
  • 举报
回复
知道怎么做了。
控制台输出的SQL语句信息如下:
Hibernate: select xmb0_.xh as xh3_, xmb0_.xmm as xmm3_, xmb0_.lbh as lbh3_, xmb0_.dlh as dlh3_, xmb0_.lx as lx3_, xmb0_.yxhj as yxhj3_, xmb0_.yy as yy3_, xmb0_.dx as dx3_, xmb0_.pj as pj3_, xmb0_.djsj as djsj3_, xmb0_.xgsj as xgsj3_, xmb0_.author as author3_, xmb0_.authorurl as authorurl3_, xmb0_.tp as tp3_, xmb0_.passwd as passwd3_, xmb0_.jj as jj3_, xmb0_.lr as lr3_, xmb0_.tj as tj3_, xmb0_.sc as sc3_ from softdown.xmb xmb0_ where dl=? order by xmb0_.xh asc
看上去没什么不对的呀?
ming1683 2007-03-06
  • 打赏
  • 举报
回复
把hibernate配置文件中的show_sql开关打开,看控制台打印的sql语句是什么
——不好意思,怎么看控制台?服务在后台,没有开控制台窗口呀?
ming1683 2007-03-06
  • 打赏
  • 举报
回复
是List list = s.createQuery(hql).setEntity("dl", dl).list();的list()这里报错
redex 2007-03-06
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/4970/4970357.xml?temp=5.991763E-02

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧