Hibernate中Hql语句问题

来源:百度知道 编辑:UC知道 时间:2024/07/01 06:58:13
org.hibernate.hql.ast.QuerySyntaxError:
unexpected token: ( near line 1, column 63
[select count(*) from com.fiberhome.jxt.study.bean.Homework a, (select new TeacherCourse(courseid,classid) from com.fiberhome.jxt.person.bean.TeacherCourse where teacherid = 1 ) b where a.classid = b.classid and a.courseid = b.courseid ]
控制台报错 说我Hql语句错了~~语句是事先在数据库里调对了才放到程序里的~~

这是程序里的拼写SQL语句,报错信息如上~~
hqlBuff.append(" from Homework a, (select new TeacherCourse(courseid,classid) from TeacherCourse where teacherid = " +QInfo.getTeacherid());
hqlBuff.append(" ) b where a.classid = b.classid and a.courseid = b.courseid ");

哪位HQL高手指导下哪里错了
前面的HomeWork作为a表~~后面根据teacherid查询出来的2个字段作为b表~~~

老版本的hql不支持子查询,新版本的支持。

但是Hibernate HQL的子查询不支持from的子查询,解决方法:

1.原sql

select * from xxx a ,(select distinct(id),max(date) time from xxx group by id) b where a.id=b.id and a.date=b.time

2.修改后hql

select * from xxx a where a.date=(select max(b.date) from xxx b where a.id=b.id group by b.id)

(select new TeacherCourse(courseid,classid) from com.fiberhome.jxt.person.bean.TeacherCourse where teacherid = 1 )

hql 不支持这种 子查询

只支持 where 后面加子查询