I have 2 classes: book and category which have a OneToMany relationship. I want to pass a list of string containing categories. The result should return all books which match any of the category in the list. for example if a book has 5 category and it matches with only 1 on the list, it should still be returned.
This is what I came up with but its not working.
//Models:
@Entity
@Table(name = "Book")
@Data
public class Book {
@Id
private String id;
@OneToMany
private List<Category> category;
}
@Entity
@Table(name="Category")
@Data
public class Category {
@Id
private int id;
private String category;
}
//
@Repository
public interface BookDao extends JpaRepository<Book, Integer> {
@Query("SELECT b FROM Book b join b.category c where c.category in :category")
Page<Book> getBooksByCat(Pageable pageable, @Param("category") List<String> category);
}
where c.category in (:category)