My code is to select the text from the parameter :title. But I got the result which is not right. In my case, class Book extends Media.
This is my query.
String queryStr = "SELECT DISTINCT(b) FROM Book b, Media m WHERE lower(m.title) LIKE :title"
TypedQuery<Book> query = em.createQuery(queryStr, Book.class);
if (book.getTitle() != null && book.getTitle() != "")
query.setParameter("title", "%" + book.getTitle().toLowerCase() + "%");
My parameter is “harry”. I suppose to get only 1 result but I got all the data that I have.
What is the mistake from my code? please help.
You should leave Media out of the query. JPA also knows Book extends Media so it knows where to get the Media part of the books.