1
votes

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.

1
So basically instead of list of ElementLog with single tag each, you want single ElementLog with list of all tags? - cst1992

1 Answers

1
votes

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.