使用spring数据和querydsl查询集合

时间:2014-06-11 13:50:40

标签: java jpa spring-data querydsl

我有以下域名模型:

@Entity
public class Sample {
  // id and other stuff
  private boolean deleted;
  private Set<Occurrence> occurrences;
  // Constructors, getter and setter
}

@Entity
public class Occurrence {
  // id and other stuff
  private boolean deleted;
  private Classification classification;
  // Constructors, getter and setter
}

@Entity
public class Classification {
   private int id;
   // other stuff
}

我想在QueryDSL和Spring Data JPA中找到所有未删除且包含发生的样本,不会被删除,并且包含一个id为47的分类。

我已经为未删除的样本创建了一个BooleanExpression:qSample.deleted.isFalse()和一个具有特定分类ID的非删除事件的SubQuery:

JPASubQuery occurrenceSubQuery = new JPASubQuery();
QOccurrence qOccurrence = QOccurrence.occurrence;
occurrenceSubQuery.from().where(
       qOccurrence.in(qSample.occurrences),
       qOccurrence.deleted.isFalse(),
       qOccurrence.classification.id
         .eq(queryId));

缺少的是:如何将这些部分组合到spring数据存储库的谓词中?

此致

丹尼尔

1 个答案:

答案 0 :(得分:0)

您可以使用

com.mysema.query.support.Expressions.allOf(...)

a.and(b).and(c)...