首页 > 代码库 > 【Hibernate】双向多对多Set查询
【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
【Hibernate】双向多对多Set查询
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。