Hibernate: Select entities where collection contains all of the specified valus

前端 未结 3 1728
闹比i
闹比i 2020-12-16 06:31

I need assistance with a tricky hibernate query problem. I have the following entities:

public class Book {
   private String bookId;
   private String autho         


        
3条回答
  •  半阙折子戏
    2020-12-16 06:57

    You could use the following query:

    select book from Book book
    where :numberOfTags = (select count(tag.id) from Book book2
                           inner join book2.tags tag
                           where book2.id = book.id
                           and tag in (:tags))
    

    where numberOfTags is the number of tags in the set of tags that must be matched.

提交回复
热议问题