jpa-子查詢

jpa子查询

 

子查询 

//select * from A  where employeeGid in (select * from B where readerGid = 'xxxx')

//子查询 from

Subquery<ReaderEmployeeRelationModel> subQuery = query.subquery(ReaderEmployeeRelationModel.class);
//子查询root获取
select * Root<ReaderEmployeeRelationModel> subRoot = subQuery.from(ReaderEmployeeRelationModel.class);
                    subQuery.select(subRoot.get("id").get("employeeGid"));
//主表与子表关联字段 指定subbquery 
Predicate readerEqual = cb.equal(subRoot.get("id").get("readerGid"), request.getOperatorGid());
                    subQuery.where(readerEqual);
//指定子查询字段
Predicate readerIn = cb.in(root.get("id").get("employeeGid")).value(subQuery);
posted @ 2019-12-30 18:02  小傻孩丶儿  阅读(459)  评论(0编辑  收藏  举报