Announcement Announcement Module
Collapse
No announcement yet.
spring-data-jpa querydsl subquery Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 04:48 PM.
Working...
X