Hql语句可以这样写么

luoxudong121316 2011-05-13 05:02:41
这样写
from Menu a where a.parent is null and (a.permission is null or a.permission in (
select distinct b from Permission b left join b.users d where d.id = ? ,
select distinct h from Permission h left join h.depts f where f.id = ? )
)
报这个错
Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: , near line 1, column 195 [from com.luoxudong.entity.Menu a where a.parent is null and (a.permission is null or a.permission in (select distinct b from com.luoxudong.entity.Permission b left join b.users d where d.id = ? ,select distinct h from com.luoxudong.entity.Permission h left join h.depts f where f.id = ? ))]



这样写
from Menu a where a.parent is null and (a.permission is null or a.permission in (
(select distinct b from Permission b left join b.users d where d.id = ? ),
(select distinct h from Permission h left join h.depts f where f.id = ?)
)
)
报这个错
Caused by: org.hibernate.HibernateException: ordinal parameter mismatch

到底该怎么写

...全文
93 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
luoxudong121316 2011-05-16
  • 打赏
  • 举报
回复
问题解决了,用下面这条hql就行,至于为什么我就不知道,如果哪位大侠知道的,教教小弟,谢谢大家
from Menu a where a.parent is null and (a.permission is null or a.permission in (
select distinct b from Permission b left join b.users d where d.id = ?) or
a.permission in (select distinct h from Permission h left join h.depts f where f.id = ? ))
pingchangxinli 2011-05-13
  • 打赏
  • 举报
回复
如果hql解决不了问题,你可以考虑用createSqlQuery创建native sql,这样就很简单的知道 sql问题所在
亲努力啊 2011-05-13
  • 打赏
  • 举报
回复
a.permission 那别用对象比用他里面的属性这样肯定行
luoxudong121316 2011-05-13
  • 打赏
  • 举报
回复
on也报错,和我第一条语句报的错是一样的
亲努力啊 2011-05-13
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 luoxudong121316 的回复:]
jianglang 你那不是和我写的一样么
[/Quote]

你那是where 我这是on
luoxudong121316 2011-05-13
  • 打赏
  • 举报
回复
jianglang 你那不是和我写的一样么
亲努力啊 2011-05-13
  • 打赏
  • 举报
回复
from Menu a where a.parent is null and (a.permission is null or a.permission in (
select distinct b from Permission b left join b.users d on d.id = ? ,
select distinct h from Permission h left join h.depts f on f.id = ? )
)
luoxudong121316 2011-05-13
  • 打赏
  • 举报
回复
对了,我忘了说了,数据库是Oracle数据库
亲努力啊 2011-05-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 luoxudong121316 的回复:]
jianglang 两个left join是并集还是交集啊,我晕
[/Quote]
并集
你用的in 可以写二条
luoxudong121316 2011-05-13
  • 打赏
  • 举报
回复
jianglang 两个left join是并集还是交集啊,我晕
亲努力啊 2011-05-13
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jianglang_a 的回复:]
from Menu a where a.parent is null and (a.permission is null or a.permission in (
select distinct b from Permission b left join b.users d on d.id = ? left join h.depts f on f.id = ? )
)
[/Quote]
先没看清是in 可以写二条
myzksky 2011-05-13
  • 打赏
  • 举报
回复
有没有写相对应的参数吗?
亲努力啊 2011-05-13
  • 打赏
  • 举报
回复
from Menu a where a.parent is null and (a.permission is null or a.permission in (
select distinct b from Permission b left join b.users d on d.id = ? left join h.depts f on f.id = ? )
)
Jio下的影子 2011-05-13
  • 打赏
  • 举报
回复
你写的这个语句在数据库能查出数据来么?

67,513

社区成员

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

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