2014-06-13 2 views
0

에 대한 술어 JPA 쿼리를 번역 : assetSet가 ManyToOne이며 OneToMany 관계를 publishings내가 (스프링 데이터 스펙) 술어로이 JPA 쿼리를 번역해야 스프링 데이터 사양

select v.id from VideoImpl v , in (v.assetSet.publishings) as p where p.channelId='23FFBE1B-65CE-4188-ADD2-C724186C2C9F' 

select videoimpl0_.id as col_0_0_ from Video videoimpl0_ inner join Asset videoimpl0_1_ on videoimpl0_.id=videoimpl0_1_.id inner join AssetSet assetsetim1_ on videoimpl0_1_.assetSetId=assetsetim1_.id left outer join AssetSet_Image assetsetim1_1_ on assetsetim1_.id=assetsetim1_1_.assetSetId inner join Publishing publishing2_ on assetsetim1_.id=publishing2_.assetSetId where publishing2_.channelId='23FFBE1B-65CE-4188-ADD2-C724186C2C9F' 

누구 단서가 있습니다

최대 절전 모드는 SQL은 다음과 같습니다 생성?

답변

1

결국 꽤 쉽게 할 수있었습니다. 나는 (*) multiselect 표현식에 익숙하지 않은 jpa 쿼리를보기보다는 생성 된 SQL에 집중했다. 작동 방식 :

private static <T> Predicate appendPublishingChannelIdCondition(Predicate predicate, ExpressionCache<T> cache, CriteriaBuilder cb, CriteriaQuery<?> query, String channelId) { 
    Subquery<String> publishingSubquery = query.subquery(String.class); 
    Root<PublishingImpl> publishingRoot = publishingSubquery.from(PublishingImpl.class); 
    Predicate channelPredicate = cb.equal(publishingRoot.get("channelId"), channelId); 
    Subquery<String> assetSetId = publishingSubquery.select(publishingRoot.<String>get("assetSetId")).where(channelPredicate); 
    Path attributePath = cache.getAttributePath("assetSet"); 
    return cb.and(predicate, attributePath.in(assetSetId)); 
}