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);
不恋尘世浮华,不写红尘纷扰