Hibernate order by 查询问题

caoliang1918 2012-10-18 12:03:55
HQL语句:

StringBuffer sbHql = new StringBuffer("SELECT NEW Employee(e.fchrEmployeeId,e.fchrEmployeeCode,
e.fchrEmployeeName,e.fdtCreateTime,e.fchrParentId,e.fchrParentName,e.fchrParentDepartment,e.fintStatus,e.fchrEmployeeEmail,e.fchrEmployeePhone,e.fchrEmployeeAddr,e.fchrEmployeeType,e.fchrEmployeeBrithday,e.fchrEmergencyPerson,e.fchrEmergencyPhone,e.fbitFresh) FROM Employee e ORDER BY e.fchrEmployeeCode DESC");

报错:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: ORDER BY 子句中的列 "HAS_Employee.fchrEmployeeCode" 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。

fchrEmployeeCode字段是字符串类型,但实际数据都是int类型,想根据它来排序。
数据库是sql server2005 之前的Mysql 好像不报错,查了好多资料还是不解。
...全文
229 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
究极装配 2013-01-29
  • 打赏
  • 举报
回复
sqlserver 的count不能order by,这和mysql不一样。要注意。
a8509190 2012-10-18
  • 打赏
  • 举报
回复
字符串怎么能排序?你在数据库把它转型啊
ld191474639 2012-10-18
  • 打赏
  • 举报
回复
绝少where关键字吧

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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