QueryDSL to get any entities in a collection of another entity

穿精又带淫゛_ 提交于 2019-12-23 17:27:55

问题


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 Tags? 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!