zoukankan      html  css  js  c++  java
  • jpa多表查询及子查询

    1. 主表1:1子表  主表查询

    1.1 **主表 MasterEntity

        

    
    
    @OneToOne
    @JoinColumn(name = "masterext")
    MasterExtendEntity masterExtendEntity; //关联表


    **子表 MasterExtendEntity

    1.2 查询

    Root<MasterEntity> root
    Path<String> code = root.join("MasterExtendEntity").get("ExtField1")
    Iterator iterator =  query.codeList.iterator()
    In invalue = cb.in(code);
    while (iterator.hasNext()) {
    invalue.value(iterator.next())
    }
    searchList.add(invalue)

    2. 主表1:1子表  子查询

    2.1

    **子表:MasterExtendEntity

    @OneToOne
    @JoinColumn(name = "MasterEntityId", nullable = false)
    MasterEntity masterEntity

    **主表 MasterEntity

    2.2查询

    //子查询
    Subquery< MasterExtendEntity> subquery = query.subquery(MasterExtendEntity)
    Root< MasterExtendEntity> extEntityRoot = subquery.from(MasterExtendEntity)
    subquery.select(extEntityRoot)


    Predicate correlatePredicate = cb.equal(extEntityRoot.get("MasterEntity"), root)
    subquery.where(
    correlatePredicate,
    cb.equal(extEntityRoot.get("code"), String), cb.equal(extEntityRoot.get("code"), String)
    )
    searchList.add(cb.exists(subquery))
  • 相关阅读:
    python shellcod加载器修改特征值
    python shellcode 分析二
    python shellcode分析
    Hadoop综合大作业1
    Hadoop综合大作业
    分布式文件系统HDFS
    安装Hadoop
    爬虫综合大作业
    爬取全部的校园新闻
    理解爬虫原理
  • 原文地址:https://www.cnblogs.com/pokay/p/8277224.html
Copyright © 2011-2022 走看看