码迷,mamicode.com
首页 > Web开发 > 详细

【Hibernate】双向多对多Set查询

时间:2014-12-15 13:35:12      阅读:131      评论:0      收藏:0      [点我收藏+]

标签: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查询

标签:des   style   blog   io   ar   color   os   sp   on   

原文地址:http://www.cnblogs.com/zengweiming/p/4164529.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!