简体   繁体   中英

Spring JPA repository, select data which contains all elements from param list

I have spring JPA Repository Interface:

public interface ElementLogRepository extends JpaRepository<ElementLog, String> 

There is Query:

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

When I call method findLatestElementLogsByTags I receive all ElementLog which contains any tag from List<Tag> tags .

How can I modify query to get all ElementLog which contains all tags from List<Tag> tags ?

Thank you in advance.

First,I think the ElementLog And Tag is related with 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()
)

my think is compare with match size,the hql should be correct, I did not actually run over.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM