hql查询返回对象问题,高手进

Rainet_yang 2012-09-04 04:47:14
hibernate如何使用sql返回对象?如下面一条sql,我想获取对象,下面的不对,请问有什么方式吗?

String hql = "select d.* from department as d where departmentid not in (select distinct parentdepartmentid from department where parentdepartmentid is not null) and departmentid <> 1";

List<Department> department = session.createSQLQuery(hql).list();


我想在同一张表中过滤掉部分数据!是根据departmentid和parentdepartmentid这两个字段。

能把这sql转换成hql语句吗?

Exception:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.chuntsuan.vo.Department;
...全文
138 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
di_wq 2012-09-05
  • 打赏
  • 举报
回复
String hql = "select d from com.chuntsuan.vo.Department d where d.departmentid not in (select distinct d2.parentdepartmentid from com.chuntsuan.vo.Department d2 where d2.parentdepartmentid is not null) and d.departmentid <> 1";
wms821 2012-09-05
  • 打赏
  • 举报
回复
String hql = "select d from com.chuntsuan.vo.Department d where d.departmentid not in (select distinct d2.parentdepartmentid from com.chuntsuan.vo.Department d2 where d2.parentdepartmentid is not null) and d.departmentid <> 1";
关键我是洛哥 2012-09-04
  • 打赏
  • 举报
回复
String hql = "select d.* from department as d where d.departmentid not in (select distinct de.parentdepartmentid from department de where de.parentdepartmentid is not null) and d.departmentid <> 1";
rucypli 2012-09-04
  • 打赏
  • 举报
回复
不清楚hql

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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