Java SpringJPA存储库,从参数列表中选择包含所有元素的数据
我有spring JPA存储库界面:Java SpringJPA存储库,从参数列表中选择包含所有元素的数据,java,spring,hibernate,spring-data,spring-data-jpa,Java,Spring,Hibernate,Spring Data,Spring Data Jpa,我有spring JPA存储库界面: public interface ElementLogRepository extends JpaRepository<ElementLog, String> public interface ElementLogRepository扩展了JpaRepository 有一个问题: @Query("SELECT pl.element.id FROM ElementLog pl WHERE pl.tags IN :tags)") public
public interface ElementLogRepository extends JpaRepository<ElementLog, String>
public interface ElementLogRepository扩展了JpaRepository
有一个问题:
@Query("SELECT pl.element.id FROM ElementLog pl WHERE pl.tags IN :tags)")
public List<ElementLog> findLatestElementLogsByTags(@Param("tags") List<Tag> tags);
@Query(“从ElementLog pl中选择pl.element.id,其中pl.tags位于:tags中)”)
公共列表findLatestElementLogsByTags(@Param(“标记”)列表标记);
当我调用方法findLatestElementLogsByTags
时,我收到所有ElementLog
,其中包含列表标记中的任何标记
如何修改查询以获取包含列表标记中所有标记的所有元素日志
首先,我认为ElementLog和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应该是正确的,我没有实际运行过。因此基本上不是使用单个标记的ElementLog
列表,而是使用包含所有标记的单个ElementLog
?