記錄本例查詢初衷:
有表:
表1,表2,表3
關系
1 many-to-one 2 2 many-to-one 3
結果:要通過表3中的條件反向查詢表1中相關的數據
public Page<WeiCommentComment> findPageWeiCommentCommentByUserid(
String userid, PageParam pageParam) {
DetachedCriteria dc = super.getDetachedCriteria();
if(StringUtils.isNotBlank(userid)){
DetachedCriteria dcwei = dc.createAlias("weiComment", "w");
dcwei.add(Restrictions.eq("user.idStr", userid));
}
Page<WeiCommentComment> page = super.findPage(dc, pageParam);
return page;
}
上面介紹:
WeiCommentComment:表1
weiComment:為表1中的定義的關聯關系
@ManyToOne(targetEntity = WeiComment.class) @JoinColumn(name="wei_id",updatable=false) private WeiComment weiComment;
user:為表2中也就是WeiComment 中的表關聯關系
@ManyToOne(targetEntity = NsanbanUser.class) @JoinColumn(name="userID",updatable=true) private NsanbanUser user;
如上介紹查詢
