2013-07-07 2 views
0

HQL에 약간의 문제가 있습니다.HQL에서 두 세트의 교집합 얻기

나는 다소 복잡한 쿼리를 수행하고 싶습니다, 나는 다음과 같은 도메인 오브젝트는 (간체) 한 :

class SomeObject { 
    Set<SomeOtherObject> otherObjects 
} 

내가 지금 모든 객체가 지정된 목록 중 하나 이상을 포함해야 느릅 나무 싶어 다른 개체의. 또한 개체를 포함해야합니다 otherObjects 블랙리스트를 가지고 싶습니다.

select o from Object as o 
join o.otherObjects as otherObject 
where 
    otherObject in :allowedotherobjects 
    and :excludedotherobject not in elements(o.otherObjects) 

은 기본적으로 내가 (수 없습니다) 같은 것을 원하는 :

나는 내가 하나의 블랙리스트 항목 및 "허용"otherObjects의 목록을 지정할 수 있습니다, 여기까지 만든

select o from Object as o 
join o.otherObjects as otherObject 
where 
    otherObject in :allowedotherobjects 
    and elements(:excludedotherobjects) not in elements(o.otherObjects) 
은 BTW이 나는 Grails의 프로젝트를 일하고 있어요,하지만 난

어떤 아이디어 HQL

에서이 문제를 해결하고 싶습니다? 나는 정말로 당신의 도움에 감사 할 것입니다!

답변

1

이 시도 :

select o from Object as o 
join o.otherObjects as otherObject 
where 
    otherObject in :allowedotherobjects 
    and otherObject not in :excludedotherobjects 
+0

또 다른 옵션은 쉬울 것 SomeOtherObject에서 조회 할 수있다. –

+0

이것은 작동하지 않는 것처럼 보입니다. "and otherObject not in : excludedotherobjects"와 같은 부분은 아무 것도하지 않습니다. otherObject에서 Query를 어떻게 수행할까요? – stba