问题
I'm using JPA with Hibernate and QueryDSL (v.4.0.5). I have this entity:
package com.test.model.entity;
@Entity
public class Article {
@Id
private Long id;
@ManyToMany(fetch = LAZY, cascade = DETACH)
private Set<Tag> tags;
}
How can I find all the articles matching a given set of Tag
s?
I think I should start as follows:
public BooleanExpression hasTag(Set<Tag> tags){
final QArticle article = QArticle.article;
return article.tags.any().eqAny(ce);
}
where ce
should be a CollectionExpression
.
Clearly I have no idea how to set this.
Any solution?
回答1:
Did you try
public BooleanExpression hasTag(Set<Tag> tags){
QArticle article = QArticle.article;
return article.tags.any().in(tags);
}
来源:https://stackoverflow.com/questions/33445572/querydsl-to-get-any-entities-in-a-collection-of-another-entity