gpt4 book ai didi

java - Spring JPA存储库,选择包含参数列表中所有元素的数据

转载 作者:行者123 更新时间:2023-11-30 07:26:16 27 4
gpt4 key购买 nike

我有 spring JPA 存储库接口(interface):

public interface ElementLogRepository extends JpaRepository<ElementLog, String> 

有查询:

@Query("SELECT pl.element.id FROM ElementLog pl WHERE pl.tags IN :tags)")
public List<ElementLog> findLatestElementLogsByTags(@Param("tags") List<Tag> tags);

当我调用方法findLatestElementLogsByTags时我收到全部ElementLog其中包含 List<Tag> tags 中的任何标签.

如何修改查询以获取所有 ElementLog其中包含 List<Tag> tags 中的所有标签?

提前谢谢您。

最佳答案

首先,我认为ElementLog And Tag与OneToMany有关。

SELECT log FROM ElementLog log WHERE log.id IN (
SELECT DISTINCT pl.id FROM ElementLog pl join pl.tags as t where t in :tags group by pl.id having count(pl.id) == :tags.size()
)

我的想法是与匹配大小进行比较,hql应该是正确的,我实际上没有跑过去。

关于java - Spring JPA存储库,选择包含参数列表中所有元素的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36770054/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com