Results 1 to 1 of 1

Thread: spring-data-jpa querydsl subquery

  1. #1
    Join Date
    Apr 2011
    Posts
    2

    Default spring-data-jpa querydsl subquery

    Hello Guys,

    I have problem with querydsl using spring-data-jpa 1.2.0.RELEASE

    I have Entity Item which has set of Promotions and each promotion has PromotionType which is an Enum. I am trying to find all items which contains set of filtered promotions where PromotionType == PromotionType.Special. I think I'll achieve that with a subquery to set of promotions like this:

    Predicate:

    public class ItemPredicates {
    private static QItem $ = QItem.item;

    public static BooleanExpression getSpecialItems() {
    return $.promotions.any().promotionType.eq(PromotionType. SPECIAL);
    }

    }

    Test:

    //prepare data
    Item item = new Item();
    item.setPromotions(Sets.newHashSet(promotion(Promo tionType.SPECIAL), promotion(PromotionType.NORMAL)));

    //assertion
    Item specialItems = itemRepository.findOne(ItemPredicates.getSpecialIt ems());


    So I'd expected item with filtered out promotions with only special type of promotion, instead I always get an item which have set of promotions. If I'll change test to this:


    Test:

    //prepare data
    Item item = new Item();
    item.setPromotions(Sets.newHashSet(promotion(Promo tionType.NORMAL)));

    //assertion
    Item specialItems = itemRepository.findOne(ItemPredicates.getSpecialIt ems());


    Then I'll get no item which is correct. I presume I need to do a subquery to set of promotions but I spend few days on investigations and still don't know how to do it with querydsl.

    Please could you give me a hand with it?
    Last edited by rosecorp; Dec 14th, 2012 at 04:48 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •