2 回答

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊
我還沒(méi)有找到解決問(wèn)題的方法,我的決定是在沒(méi)有規(guī)范的情況下使用實(shí)體管理器“手動(dòng)創(chuàng)建”查詢(xún)。
final String queryString = "select distinct pos from Position pos " +
"inner join pos.managersPositions mn " +
"where mn.managerId = :managerId and mn.isDirect = :isDirect ";
TypedQuery<Position> query = entityManager.createQuery(
queryString,
Position.class);
query.setParameter("managerId", managerEmployeeId);
query.setParameter("isDirect", true);
因?yàn)楫?dāng)我制作它時(shí)criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));,它只制作了一個(gè)帶有一個(gè)參數(shù)的謂詞。
還嘗試將規(guī)格分為 2,結(jié)果不成功:
Specification.where(firstSpecification).and(secondSpecification)

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
使用 CriteriaBuilder.parameter() 添加多個(gè)參數(shù):
ParameterExpression<Integer> managerIdParam =
criteriaBuilder.parameter( Integer.class );
ParameterExpression<Boolean> isDirectParam =
criteriaBuilder.parameter( Boolean.class );
Predicate managerPredicate =
criteriaBuilder.equal(managersPositionsJoin.get("managerId"),
managerIdParam);
Predicate equalsDirect =
criteriaBuilder.equal(managersPositionsJoin.get("isDirect"), isDirectParam);
添加回答
舉報(bào)