如何在联接多个表时使用 JPA 条件 API
2022-09-04 06:57:58
这是进一步的问题:
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<Company> criteria = criteriaBuilder.createQuery( Company.class );
Root<Company> companyRoot = criteria.from( Company.class );
Join<Company,Product> products = companyRoot.join("dentist");
Join<Company, City> cityJoin = companyRoot.join("address.city");//Company->Address->City-city
criteria.where(criteriaBuilder.equal(products.get("category"), "dentist"), criteriaBuilder.equal(cityJoin.get("city"),"Leeds"));
一家公司有一个地址,地址里面有City-pojo和Country-Pojo。我该如何使用它?我试图引用它,但我收到错误消息:JOIN
address.city
托管类型 [EntityTypeImpl@1692700229:Company [ javaType: class com.test.domain.Company 描述符: RelationalDescriptor(com.test.domain.Company --> [DatabaseTable(COMPANY)]) 中的属性 [address.city] 不存在,映射:16]]。