I have issue with simple SELECT query with join clause.
I am trying to get Author with list of its Books. My query looks like:
public Author findAuthorWithBooks(Integer authorId) {
return (Author) em.createQuery("SELECT a FROM Author a LEFT JOIN a.books WHERE a.id = :authorId")
.setParameter("authorId", authorId)
.getSingleResult();
}
But when code is running I am getting ArgumentException: Encounter "" at character xx, but expected: []
Simplified entities looks like that:
public class Author {
@OneToMay(mappedBy = "author", fetch=LAZY)
private Collections<Book> books;
}
public class Book {
@ManyToOne(fetch=LAZY)
@JoinColumn(name="AUTHOR_ID")
private Collections<Book> books;
}
I suppose I did some pretty stupid mistake, but I cant find it.
Either this is a typo in your question or your
Bookclass is wrong. It should be as follows:Additionally, your query does not seem right. Try the following: