• 【Hibernate】双向多对多Set查询


    一个计划对于多个竞价,一个竞价对应多个计划。

    1.实体

    /**
     * @author Tidy
     * @Description 计划
     */
    public class EbgStockPlanContent extends Model {
      /***省略***/
      private Set<EbgBidding> biddingSet = new HashSet<EbgBidding>();
      /***省略getset***/
    }
    
    /**
     * @author Tidy
     * @Description 竞价
     */
    public class EbgStockPlanContent extends Model {
      /***省略***/
      private Set<EbgStockPlanContent> planSet = new HashSet<EbgStockPlanContent>();
      /***省略getset***/
    }

    2.多对多配置(xml方式)

    <set name="biddingSet" table="T_EB_BIDDING_PLAN_COMPOSE" cascade="none" inverse="false" lazy="true">
      <key column="PLAN_CONTENT_ID"></key>
      <many-to-many class="gdgpes.ebg.model.bid.EbgBidding" column="BIDDING_ID"></many-to-many>
    </set>
    
    <set name="planSet" table="T_EB_BIDDING_PLAN_COMPOSE" cascade="none" inverse="false" lazy="true">
      <key column="BIDDING_ID"></key>
      <many-to-many class="gdgpes.ebg.model.plan.EbgStockPlanContent" column="PLAN_CONTENT_ID"></many-to-many>
    </set>

    3.测试

    4.elements()操作set集合

    //remark
    hql.append(" and mo.id not in (").append("select elements(planSet) from EbgBidding t1 where t1.type = 1").append(") and mo.price=5 ");
    //1.直接查询set记录
    select elements(planSet) from EbgBidding t1 where t1.type = 1
    //2.in set记录
    and mo.id not in elements(mo.biddingSet)

    上例1.对应生成的sql
    select planset2_.PLAN_CONTENT_ID
    from T_EB_BIDDING ebgbidding1_,
         T_EB_BIDDING_PLAN_COMPOSE planset2_
    where ebgbidding1_.ID = planset2_.BIDDING_ID
    and ebgbidding1_.TYPE = 1
  • 相关阅读:
    lintcode:previous permutation上一个排列
    lintcode : 二叉树的序列化和反序列化
    lintcode : find peak element 寻找峰值
    lintcode 中等题:搜索旋转排序数组II
    lintcode :搜索旋转排序数组
    lintcode: search for a range 搜索区间
    lintcode:最大子数组差
    lintcode:最大子数组II
    lintcode :最大子数组
    lintcode : 平衡二叉树
  • 原文地址:https://www.cnblogs.com/zengweiming/p/4164529.html
Copyright © 2020-2023  润新知