简体   繁体   English

带有Spring数据和querydsl的查询集合

[英]Queries collections with spring data and querydsl

I have the following domain model: 我有以下域模型:

@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
}

I want to find with QueryDSL and Spring Data JPA all Samples which are not deleted and contain an occurrence witch is not deleted and contains a classification with the id 47. 我想使用QueryDSL和Spring Data JPA查找未删除并包含出现事件的所有示例,并且未删除并包含ID为47的分类。

I allready have a BooleanExpression for the not deleted samples: qSample.deleted.isFalse() and a SubQuery for the not delted occurrence which has a certain classification id: 我已经为未删除的样本准备了一个BooleanExpression: qSample.deleted.isFalse()和一个没有查询的子查询,该查询具有一定的分类ID:

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

What's missing is: how to bring these parts together to a predicate for the spring data repository? 缺少的是:如何将这些部分放到spring数据存储库的谓词中?

Regards 问候

Daniel 丹尼尔

You can use 您可以使用

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

or 要么

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM