JPA2 그립을 시도하고 몇 가지 조인을 시도하는 하나의 결과를 얻으려고. 여기에 내가 지금 시도한 바가있다 :여러 조인 JPA2
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<FileCollection> cq = cb.createQuery(getEntityClass()); // getEntityClass() will return FileCollection.class
Root<FileCollection> collectionRoot = cq.from(getEntityClass());
Join<FileCollection, Repository> repositories = collectionRoot.join(FileCollection_.repository);
Join<Repository, Customer> customers = repositories.join(Repository_.customer);
cq.select(collectionRoot);
cq.where(cb.equal(customers.get(Customer_.name), customerName),
cb.equal(repositories.get(Repository_.name), repositoryName) ,
cb.equal(collectionRoot.get(FileCollection_.folderName), folderName)
);
return getEntityManager().createQuery(cq).getSingleResult();
이것은 작동하지 않는다. 두 번째 & where 매개 변수의 세 번째 매개 변수를 주석 처리하면 작동합니다 (고객 이름 만 제공 할 것입니다). 그래서 나는 잘못된 것을 얻고있다. 나는 단지 무엇이 있는지 모른다! 다음은 SQL로 표현하고자하는 쿼리입니다.
SELECT f.*
FROM filecollection f
JOIN repository r ON f.REPOSITORY_ID = r.REPOSITORY_ID
JOIN customer c ON r.CUSTOMER_ID = c.CUSTOMER_ID
WHERE c.NAME = 'X' AND r.NAME = 'Y' AND f.FOLDER_NAME = 'Z';
누구든지 나를 도와 주며 실수를 지적 할 수 있습니까? 그 사이에 JPA2 책으로 돌아가서 내가 이것을 알아낼 수 있는지 알아볼 것입니다!
모든 예외 스택 추적? – DaTroop
NoResultsException입니다. 전달하는 매개 변수는 정확하지만 내 쿼리가 정확하면 결과를 얻을 것으로 기대합니다. –