Error: Cannot create TypedQuery for query with more than one return
java, jpa, postgresql, sql
Solution
Without goind into details about how `Media` and `Book` should be modeled, I will at least explain why you get this exception.
You're doing:
em.createQuery(someJPQL, Media.class);
This means: create a query using `someJPQL`, and this query will return instances of the `Media` entity.
But your `JPQL` is:
SELECT m.title, b.isbn, b.authors ...
So the query does not return entities of type Media. It returns three fields, from two different entities. There is no way your JPA engine could magically create instances of Media from these 3 columns. A query would return instances of Media if it looked like this:
select m from Media m ...
Problem
I try to do the function searchBook with java and jpa. I have 2 classes which are Media and Book. Book extends Media. And I keep the data in the different table. I try to select the data from the query below: ``` TypedQuery<Media> query = em.createQuery( "SELECT m.title, b.isbn, b.authors" + " FROM Book b, Media m" + " WHERE b.isbn = :isbn" + " OR lower(m.title) LIKE :title" + " OR b.authors LIKE :authors", Media.class); query.setParameter("isbn", book.getisbn()); query.setParameter("title", "%" + book.getTitle().toLowerCase() + "%"); query.setParameter("authors", "%" + book.getAuthors() + "%"); bookList = query.getResultList(); ``` But I got the error: java.lang.IllegalArgumentException: Cannot create TypedQuery for query with more than one return This is the first time I use JPA. I can't find the the mistake.