项目里面有三个实体类 如:
package com.newer.pojo;public class Country {
private Integer CountryID;
private String CountryName;
private Medal medal;
......
package com.newer.pojo;public class Event {
private Integer EventID;
private String EventName;
private Medal medal;
......package com.newer.pojo;import java.util.Date;public class Medal {
private Integer MedalID;
private String MedalType;//奖牌类型
private Date AwardDate;
private Country country;
private Event event;
现在是要求在网页上显示 :名次,得奖的国家,金牌数,银牌数,铜牌数
名次是按金牌数排名
如果先不考虑排名 Query 语句这样写执行时报错(Query q = session.createQuery("select c.CountryName,count(m.MedalType='金牌'),count(m.MedalType='银牌'),count(m.MedalType='铜牌') from Medal as m right outer join m.country as c ");下面是网页报的错:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '=' near line 1, column 39 [select c.CountryName,count(m.MedalType='金牌'),count(m.MedalType='银牌'),count(m.MedalType='铜牌') from com.newer.pojo.Medal as m right outer join m.country as c ]
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)
com.newer.dao.MedalDao.findAll(MedalDao.java:23)
com.newer.web.MedalOrderAction.execute(MedalOrderAction.java:10)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
......如果要排名的话该怎么写Hql 语句?我再次感谢大家了啊
package com.newer.pojo;public class Country {
private Integer CountryID;
private String CountryName;
private Medal medal;
......
package com.newer.pojo;public class Event {
private Integer EventID;
private String EventName;
private Medal medal;
......package com.newer.pojo;import java.util.Date;public class Medal {
private Integer MedalID;
private String MedalType;//奖牌类型
private Date AwardDate;
private Country country;
private Event event;
现在是要求在网页上显示 :名次,得奖的国家,金牌数,银牌数,铜牌数
名次是按金牌数排名
如果先不考虑排名 Query 语句这样写执行时报错(Query q = session.createQuery("select c.CountryName,count(m.MedalType='金牌'),count(m.MedalType='银牌'),count(m.MedalType='铜牌') from Medal as m right outer join m.country as c ");下面是网页报的错:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '=' near line 1, column 39 [select c.CountryName,count(m.MedalType='金牌'),count(m.MedalType='银牌'),count(m.MedalType='铜牌') from com.newer.pojo.Medal as m right outer join m.country as c ]
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)
com.newer.dao.MedalDao.findAll(MedalDao.java:23)
com.newer.web.MedalOrderAction.execute(MedalOrderAction.java:10)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
......如果要排名的话该怎么写Hql 语句?我再次感谢大家了啊
解决方案 »
- 请问关于tomcat5.5下跑两个应用的配置问题
- 以前用的是GlassFish v3的服务器,后来把服务器改成Tomcat 6.0之后,servlet就报错.
- 高手请进,一个用JST和AJAX中DWR作的一个小例子,小弟多时起步,请指点迷津!!在这谢过
- hibernate初学一问
- 第一次用log4j,总是出现log4j:WARN File option not set for appender [A1].错误,怎么办??
- 请问jsp如何实现短信收发模块
- 在线等,如何防止在页面连续点击两次提交按钮,造成后台数据库增加两条记录?
- ====有点难度的问题====
- MYSQL和JBDC如何使用怎么设置变量,(在线等)
- 请问各位,getYear()得到的当前年,怎么是102?
- ★★高分求:麻烦推荐从CS转BS的监控项目推荐开发模式★★
- A表 B表 C表 关系维护问题
(select Country_id,count(id) as num from Medal where MedalType='铜牌' group by Country_id) as b on xx.id=b.Country_id left join
(select Country_id,count(id) as num from Medal where MedalType='铜牌' group by Country_id) as c on xx.id=c.Country_id
order by a.num
(select Country_id,count(id) as num from Medal where MedalType='银牌' group by Country_id) as b on xx.id=b.Country_id left join
(select Country_id,count(id) as num from Medal where MedalType='铜牌' group by Country_id) as c on xx.id=c.Country_id
order by a.num