I have a problem with my custom query made with criteria query, I need to make an In clause on a field that has a many to many relationship, what is the best way?
here is the entity
public class Book {
private int idBook;
//bi-directional many-to-many association to Author
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name="book_author"
, joinColumns={
@JoinColumn(name="idBook")
}
, inverseJoinColumns={
@JoinColumn(name="idAuthor")
}
)
private Set<Author> authors;
here is my wrong attempt
if (filterValue.getAuthors() != null) {
In<Integer> authorsInId = cb.in(root.get("authors"));
for (AuthorsPOJO subsystem : filterValue.getAuthors()) {
authorsInId.value(authors.getIdAuthor());
}
predicates.add(authorsInId);
}
thanks