简体   繁体   English

QueryDSL以获取另一个实体集合中的任何实体

[英]QueryDSL to get any entities in a collection of another entity

I'm using JPA with Hibernate and QueryDSL (v.4.0.5). 我正在将JPA与Hibernate和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? 如何找到与给定Tag集合匹配的所有文章? 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 . ce应该是CollectionExpression Clearly I have no idea how to set this. 显然我不知道该如何设置。

Any solution? 有什么办法吗?

Did you try 你试过了吗

public BooleanExpression hasTag(Set<Tag> tags){
    QArticle article = QArticle.article;
    return article.tags.any().in(tags);
}

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

相关问题 删除实体,它是集合的元素,并且在Hibernate中具有另一个实体的集合 - Deleting entity, which is element of collection and has collection of another entities in Hibernate 我可以使用manyToMany关系在另一个实体上拥有一组实体吗? - Am I able to have a collection of Entities on another Entity using a manyToMany relationship? QUERYDSL:无法获取继承的实体中主键的查询类型 - QUERYDSL: Unable to get query type for primary key in the inherited entity QueryDsl - 集合表达式中的子查询 - QueryDsl - subquery in collection expression 在Hibernate中使用另一个引用的实体插入/更新一个实体 - Inserting/Updating an entity with another referenced entities in Hibernate 使用Hibernate在另一个实体中保存一组实体 - Saving an array of Entities in another entity with Hibernate 如何在不返回根实体的情况下返回休眠集合实体 - How to return hibernate collection entities without returning root entity 如何使用 map 在实体内部使用 Hibernate 实体集合? - How to map a collection of entities, inside an entity, using Hibernate? 从具有多个实体的映射器中获取实体 - get an Entity from a mapper with several Entities 使用QueryDSL按唯一字段查找实体 - Find entity by unique field with QueryDSL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM