开发者社区> 问答> 正文

hibernate 左连接 如何加连接条件?报错

HQL :

FROM  FileCheckOrg as fco right outer join fco.org as o WITH o.semesterId =? where fco.type=?

生成sql如下:


select
        filechecko0_.id as id6_0_,
        org1_.id as id10_1_,
        filechecko0_.title as title6_0_,
        filechecko0_.author_id as author3_6_0_,
        filechecko0_.author_name as author4_6_0_,
        filechecko0_.click_count as click5_6_0_,
        filechecko0_.state as state6_0_,
        filechecko0_.type as type6_0_,
        filechecko0_.create_time as create8_6_0_,
        filechecko0_.file_id as file9_6_0_,
        filechecko0_.org_id as org10_6_0_,
        org1_.clazz_id as clazz2_10_1_,
        org1_.clazz_name as clazz3_10_1_,
        org1_.grade_id as grade4_10_1_,
        org1_.grade_name as grade5_10_1_,
        org1_.semester_id as semester6_10_1_,
        org1_.semester_name as semester7_10_1_,
        org1_.create_time as create8_10_1_ 
    from
        tb_kms_file_check_org filechecko0_ 
    right outer join
        tb_kms_org org1_ 
            on filechecko0_.org_id=org1_.id 
            and (
                org1_.semester_id=?
            ) 
    where
        filechecko0_.type=? limit ?

希望能把条件加在on后面,WITH 只能有一个条件,多条件是会报错,错误如下:

with-clause referenced two different from-clause elements



展开
收起
爱吃鱼的程序员 2020-06-22 16:57:53 442 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    selectfilechecko0_.*
     fromtb_kms_file_check_orgfilechecko0_
     rightouterjoin(selectorg1_.*
               fromtb_kms_orgorg1_
              whereorg1_.semester_id=?)rgt
      onfilechecko0_.org_id=rgt.id
     wherefilechecko0_.type=?limit?

    链接查询语法是 

    SELECT*FROM表1 INNERJOIN表2ON表1.字段号=表2.字段号
    2020-06-22 16:58:11
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载