Reputation: 13666
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?
Upvotes: 4
Views: 4939
Reputation: 22180
Did you try
public BooleanExpression hasTag(Set<Tag> tags){
QArticle article = QArticle.article;
return article.tags.any().in(tags);
}
Upvotes: 5