【Hibernate】雙向多對多Set查詢

來源:互聯網
上載者:User

標籤:des   style   blog   io   ar   color   os   sp   on   

一個計劃對於多個競價,一個競價對應多個計劃。

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

 

【Hibernate】雙向多對多Set查詢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.