I have an entity Book
which contain List of Author
entity.
Book
ManyToMany Author
Book Entity
public class Book{
...
@ManyToMany
@JoinTable(name="BookAuthor",
joinColumns={@JoinColumn(name="bookId")},
inverseJoinColumns={@JoinColumn(name="authorId")})
private List<Author> authors;
...
}
Note: There is no backward reference from Author to Book in Author entity.
I am trying to get all the books that have the exact list of authors.
This is what I have come up with so far:-
public List<Book> getBooksFromAuthors(List<Author> authors) {
TypedQuery<Book> bookTypedQuery = entityManager.createQuery("SELECT b FROM Book b where b.authors = :authors", Book.class)
.setParameter("authors", authors);
return bookTypedQuery.getResultList(); // Error at this line
}
This gives an error:-
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
How should I modify my query to get the desired result?