HQL 语句报错 join 复杂sql语句 求助!

J2EE 码拜 9年前 (2015-05-10) 934次浏览 0个评论
 

@Override
    public  Info findBySex(Boolean sex){
        return (Info)this.getSession().createQuery(”  from Info   as t1 join (select ROUND(rand()*(select max(bid) from Info ) )  as bid)as t2  where t1.bid>=t2.bid and bsex=?0 and bbutto = true order by t1.bid asc limit 1  “)
                .setParameter(“0”, sex).uniqueResult();
    }

报错了!  我的sql在MYSQL执行语句不会报错:

select * from info   as t1 join (select ROUND(rand()*(select max(bid) from info ) )  as bid)as t2 
where t1.bid>=t2.bid and bsex=0 order by t1.bid asc limit 1;  求帮助

40分
hql里没有limit吧
还有hql里面,查询的表是用类名代替的,区分大小写
引用 2 楼 guoweiqaz 的回复:

还有hql里面,查询的表是用类名代替的,区分大小写

我懂 只是刚好不巧 建了个小写开头的model  算了 我直接返回要的字段 执行sql语句了

你这hql语句有问题啊,连接查询怎么会是这样写的呢?hql中是 : 对象  join  对象  on ..   。sql中是 表1 ioin 表2 on…   。(select ROUND(rand()*(select max(bid) from info ) )  as bid)这个查出来的不是对象也不是表 ,只是一个查询的结果。这就相当于 对象 ioin 查询结果  on …。 这样怎能不报错呢
一楼说得对,hql里面没有limit ,通过query.setFirstResult()和setMaxResult()来实现分页查询

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明HQL 语句报错 join 复杂sql语句 求助!
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!