jpa-サブクエリ

5031 ワード

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);