CriteriaBuilder 联合查询

public List findProdFactoryDesc(String prodtype, String prodName) {

CriteriaBuilder cb = entityManager.getCriteriaBuilder();

CriteriaQuery cq = cb.createQuery(String.class);

Root prt = cq.from(Product.class);

Root fct =cq.from(Factory.class);

Predicate pType=cb.equal(prt.get("type"), prodtype);

Predicate pName=cb.equal(prt.get("name"),prodName);

Predicate prtAnd=cb.and(pType,pName);

Predicate facType=cb.equal(fct.get("prodType"), prodtype);

Predicate facName=cb.equal(fct.get("prodName"),prodName);

Predicate facAnd=cb.and(facType,facName);

Predicate prtFacAnd=cb.and(prtAnd,facAnd);

cq.where(prtFacAnd);

cq.multiselect(fct.get("ftyDesc")).distinct(true);

List list = entityManager.createQuery(cq).getResultList();

return list;

}

你可能感兴趣的:(windows,microsoft,linux)