jpa-子查詢

jpa子查询

 

子查询 

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

//子查询 from

Subquery subQuery = query.subquery(ReaderEmployeeRelationModel.class);
//子查询root获取
select * Root 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);

你可能感兴趣的:(jpa-子查詢)