hibernate hql语句查询报错org.hibernate.hql.ast.QuerySyntaxException:
sql语句没错,但是改成hql后却报了org.hibernate.hql.ast.QuerySyntaxException这个错误,原sql为“selects.title...
sql语句没错,但是改成hql后却报了org.hibernate.hql.ast.QuerySyntaxException这个错误,原sql为
“select
s.title,count(distinct(o.id)) onum ,count(distinct(i.userid)) unum
from
v_subject s left join v_option o on s.id = o.sid left join v_item i on s.id = i.sid
group by s.title ;”
改成的hql为
sb.append("select ");
sb.append("s.title,count(distinct(o.id)) onum ,count(distinct(i.vuser.userId)) unum ");
sb.append("from ");
sb.append("Subject s left join Option o on s.id = o.subject.id left join Item i on s.id = i.vsubject.id ");
sb.append("group by s.title");
报的错如下:Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 30 [select s.title,count(distinct(o.id)) onum ,count(distinct(i.vuser.userId)) unum from entity.Subject s left join Option o on s.id = o.subject.id left join Item i on s.id = i.vsubject.id group by s.title]
求解 展开
“select
s.title,count(distinct(o.id)) onum ,count(distinct(i.userid)) unum
from
v_subject s left join v_option o on s.id = o.sid left join v_item i on s.id = i.sid
group by s.title ;”
改成的hql为
sb.append("select ");
sb.append("s.title,count(distinct(o.id)) onum ,count(distinct(i.vuser.userId)) unum ");
sb.append("from ");
sb.append("Subject s left join Option o on s.id = o.subject.id left join Item i on s.id = i.vsubject.id ");
sb.append("group by s.title");
报的错如下:Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 30 [select s.title,count(distinct(o.id)) onum ,count(distinct(i.vuser.userId)) unum from entity.Subject s left join Option o on s.id = o.subject.id left join Item i on s.id = i.vsubject.id group by s.title]
求解 展开
2个回答
展开全部
sb.append("select ");
sb.append("new map(s.title,count(distinct(o.id)) onum ,count(distinct(i.vuser.userId)) unum )");
sb.append("from ");
sb.append("Subject s left join Option o left join Item i ");
定义中,有关联,不需要写on
sb.append("new map(s.title,count(distinct(o.id)) onum ,count(distinct(i.vuser.userId)) unum )");
sb.append("from ");
sb.append("Subject s left join Option o left join Item i ");
定义中,有关联,不需要写on
追问
还是报了错,能不能加我QQ ,明天有时间了帮我看一下?
展开全部
hql 是 有专门的语法的。 不是sql。你把hibernate方言设置成你用的数据库。。。
例如你是用oracle数据库:
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
例如你是用oracle数据库:
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
追问
恩,这个知道,就是不知道hql语句错到哪了?
追答
hql 语法你去看看就知道,你错哪里了。sql的语法和hql不是一回事。
.QuerySyntaxException是说,你要的sql不是hql,语法错误。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询